[PATCH] D106368: [AlignmentFromAssumptions] avoid crash on alignment constant expression
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 20 08:20:17 PDT 2021
spatel created this revision.
spatel added reviewers: nikic, jdoerfert.
Herald added subscribers: javed.absar, hiraditya, mcrosier.
spatel requested review of this revision.
Herald added a project: LLVM.
I'm not familiar with this pass, but we have a crash shown in:
https://llvm.org/PR50978
...so I think we can either bail out as shown here or dyn_cast later to avoid the assert failure in getNewAlignmentDiff() that happens with the plain `cast<SCEVConstant>`.
https://reviews.llvm.org/D106368
Files:
llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
llvm/test/Transforms/AlignmentFromAssumptions/simple.ll
Index: llvm/test/Transforms/AlignmentFromAssumptions/simple.ll
===================================================================
--- llvm/test/Transforms/AlignmentFromAssumptions/simple.ll
+++ llvm/test/Transforms/AlignmentFromAssumptions/simple.ll
@@ -252,6 +252,21 @@
; CHECK: ret i32 undef
}
+; Don't crash on constant expression.
+
+ at g = global i32 0
+
+define void @PR50978(i32* %arg) {
+; CHECK-LABEL: @PR50978(
+; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i32* [[ARG:%.*]], i64 zext (i32 ptrtoint (i32* @g to i32) to i64)) ]
+; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[ARG]], align 4
+; CHECK-NEXT: ret void
+;
+ call void @llvm.assume(i1 true) [ "align"(i32* %arg, i64 zext (i32 ptrtoint (i32* @g to i32) to i64)) ]
+ load i32, i32* %arg
+ ret void
+}
+
declare void @llvm.assume(i1) nounwind
declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
Index: llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
+++ llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
@@ -220,6 +220,9 @@
// TODO: Consider accumulating the offset to the base.
AAPtr = AAPtr->stripPointerCastsSameRepresentation();
AlignSCEV = SE->getSCEV(AlignOB.Inputs[1].get());
+ // We only handle a simple constant (constant expressions not allowed).
+ if (!isa<SCEVConstant>(AlignSCEV))
+ return false;
AlignSCEV = SE->getTruncateOrZeroExtend(AlignSCEV, Int64Ty);
if (AlignOB.Inputs.size() == 3)
OffSCEV = SE->getSCEV(AlignOB.Inputs[2].get());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106368.360142.patch
Type: text/x-patch
Size: 1633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210720/531260c5/attachment.bin>
More information about the llvm-commits
mailing list