Skip to content

Commit 97c0df5

Browse files
committed
[AlignmentFromAssumes] Handle non-power-of-two alignment (PR64687)
Align operand bundles can contain non-power-of-two alignments, but LLVM otherwise does not support them. Bail out in that case instead of crashing. Fixes llvm#64687.
1 parent d047342 commit 97c0df5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ bool AlignmentFromAssumptionsPass::extractAlignmentInfo(CallInst *I,
179179
// Added to suppress a crash because consumer doesn't expect non-constant
180180
// alignments in the assume bundle. TODO: Consider generalizing caller.
181181
return false;
182+
if (!cast<SCEVConstant>(AlignSCEV)->getAPInt().isPowerOf2())
183+
// Only power of two alignments are supported.
184+
return false;
182185
if (AlignOB.Inputs.size() == 3)
183186
OffSCEV = SE->getSCEV(AlignOB.Inputs[2].get());
184187
else

llvm/test/Transforms/AlignmentFromAssumptions/simple.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,20 @@ entry:
381381
ret i32 %0
382382
}
383383

384+
define i32 @pr64687(ptr nocapture %a) {
385+
; CHECK-LABEL: define i32 @pr64687
386+
; CHECK-SAME: (ptr nocapture [[A:%.*]]) {
387+
; CHECK-NEXT: entry:
388+
; CHECK-NEXT: tail call void @llvm.assume(i1 true) [ "align"(ptr [[A]], i32 123) ]
389+
; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[A]], align 4
390+
; CHECK-NEXT: ret i32 [[TMP0]]
391+
;
392+
entry:
393+
tail call void @llvm.assume(i1 true) ["align"(ptr %a, i32 123)]
394+
%0 = load i32, ptr %a, align 4
395+
ret i32 %0
396+
}
397+
384398
declare void @llvm.assume(i1) nounwind
385399

386400
declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1) nounwind

0 commit comments

Comments
 (0)