Skip to content

Commit 703ee97

Browse files
preameststellar
authored andcommitted
[AlignFromAssume] Bailout w/non-constant alignments (pr51680)
This is a bailout for pr51680. This pass appears to assume that the alignment operand to an align tag on an assume bundle is constant. This doesn't appear to be required anywhere, and clang happily generates non-constant alignments for cases such as this case taken from the bug report: // clang -cc1 -triple powerpc64-- -S -O1 opal_pci-min.c extern int a[]; long *b; long c; void *d(long, int *, int, long, long, long) __attribute__((__alloc_align__(6))); void e() { b = d(c, a, 0, 0, 5, c); b[0] = 0; } This was exposed by a SCEV change which allowed a non-constant alignment to reach further into the pass' code. We could generalize the pass, but for now, let's fix the crash. (cherry picked from commit 9b45fd9)
1 parent d597db1 commit 703ee97

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ bool AlignmentFromAssumptionsPass::extractAlignmentInfo(CallInst *I,
221221
AAPtr = AAPtr->stripPointerCastsSameRepresentation();
222222
AlignSCEV = SE->getSCEV(AlignOB.Inputs[1].get());
223223
AlignSCEV = SE->getTruncateOrZeroExtend(AlignSCEV, Int64Ty);
224+
if (!isa<SCEVConstant>(AlignSCEV))
225+
// Added to suppress a crash because consumer doesn't expect non-constant
226+
// alignments in the assume bundle. TODO: Consider generalizing caller.
227+
return false;
224228
if (AlignOB.Inputs.size() == 3)
225229
OffSCEV = SE->getSCEV(AlignOB.Inputs[2].get());
226230
else

llvm/test/Transforms/AlignmentFromAssumptions/simple.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,19 @@ entry:
252252
; CHECK: ret i32 undef
253253
}
254254

255+
256+
; Variable alignments appear to be legal, don't crash
257+
define i32 @pr51680(i32* nocapture %a, i32 %align) nounwind uwtable readonly {
258+
entry:
259+
tail call void @llvm.assume(i1 true) ["align"(i32* %a, i32 %align)]
260+
%0 = load i32, i32* %a, align 4
261+
ret i32 %0
262+
263+
; CHECK-LABEL: @pr51680
264+
; CHECK: load i32, i32* {{[^,]+}}, align 4
265+
; CHECK: ret i32
266+
}
267+
255268
declare void @llvm.assume(i1) nounwind
256269

257270
declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind

0 commit comments

Comments
 (0)