[llvm-branch-commits] [llvm] 703ee97 - [AlignFromAssume] Bailout w/non-constant alignments (pr51680)

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Sep 1 17:36:52 PDT 2021


Author: Philip Reames
Date: 2021-09-01T17:36:37-07:00
New Revision: 703ee975d26a1542e2a431722af0ce904a0ca149

URL: https://github.com/llvm/llvm-project/commit/703ee975d26a1542e2a431722af0ce904a0ca149
DIFF: https://github.com/llvm/llvm-project/commit/703ee975d26a1542e2a431722af0ce904a0ca149.diff

LOG: [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 9b45fd909ffa754acbb4e927bc2d55c7ab0d4e3f)

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
    llvm/test/Transforms/AlignmentFromAssumptions/simple.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp b/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
index be21db9087d2e..e4ec5f266eb85 100644
--- a/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
+++ b/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
@@ -221,6 +221,10 @@ bool AlignmentFromAssumptionsPass::extractAlignmentInfo(CallInst *I,
   AAPtr = AAPtr->stripPointerCastsSameRepresentation();
   AlignSCEV = SE->getSCEV(AlignOB.Inputs[1].get());
   AlignSCEV = SE->getTruncateOrZeroExtend(AlignSCEV, Int64Ty);
+  if (!isa<SCEVConstant>(AlignSCEV))
+    // Added to suppress a crash because consumer doesn't expect non-constant
+    // alignments in the assume bundle.  TODO: Consider generalizing caller.
+    return false;
   if (AlignOB.Inputs.size() == 3)
     OffSCEV = SE->getSCEV(AlignOB.Inputs[2].get());
   else

diff  --git a/llvm/test/Transforms/AlignmentFromAssumptions/simple.ll b/llvm/test/Transforms/AlignmentFromAssumptions/simple.ll
index 80761ad3be6b2..d8b1c618e74bd 100644
--- a/llvm/test/Transforms/AlignmentFromAssumptions/simple.ll
+++ b/llvm/test/Transforms/AlignmentFromAssumptions/simple.ll
@@ -252,6 +252,19 @@ entry:
 ; CHECK: ret i32 undef
 }
 
+
+; Variable alignments appear to be legal, don't crash
+define i32 @pr51680(i32* nocapture %a, i32 %align) nounwind uwtable readonly {
+entry:
+  tail call void @llvm.assume(i1 true) ["align"(i32* %a, i32 %align)]
+  %0 = load i32, i32* %a, align 4
+  ret i32 %0
+
+; CHECK-LABEL: @pr51680
+; CHECK: load i32, i32* {{[^,]+}}, align 4
+; CHECK: ret i32
+}
+
 declare void @llvm.assume(i1) nounwind
 
 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind


        


More information about the llvm-branch-commits mailing list