[llvm] 5d1ba53 - [LoopReroll] Add an extra defensive check to avoid SCEV assertion.

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 13 12:17:25 PDT 2021


Author: Eli Friedman
Date: 2021-07-13T12:17:09-07:00
New Revision: 5d1ba534043707a7b41542e9d1e514483f88503a

URL: https://github.com/llvm/llvm-project/commit/5d1ba534043707a7b41542e9d1e514483f88503a
DIFF: https://github.com/llvm/llvm-project/commit/5d1ba534043707a7b41542e9d1e514483f88503a.diff

LOG: [LoopReroll] Add an extra defensive check to avoid SCEV assertion.

Make sure getMinusSCEV() didn't return a pointer.  The following check
would never succeed if it was a pointer, anyway, but calling
getMulExpr() on a pointer SCEV now asserts.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
    llvm/test/Transforms/LoopReroll/basic.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp b/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
index 98889f9a19dfe..56d66b93dd691 100644
--- a/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
@@ -911,7 +911,7 @@ bool LoopReroll::DAGRootTracker::validateRootSet(DAGRootSet &DRS) {
   // Check that the first root is evenly spaced.
   unsigned N = DRS.Roots.size() + 1;
   const SCEV *StepSCEV = SE->getMinusSCEV(SE->getSCEV(DRS.Roots[0]), ADR);
-  if (isa<SCEVCouldNotCompute>(StepSCEV))
+  if (isa<SCEVCouldNotCompute>(StepSCEV) || StepSCEV->getType()->isPointerTy())
     return false;
   const SCEV *ScaleSCEV = SE->getConstant(StepSCEV->getType(), N);
   if (ADR->getStepRecurrence(*SE) != SE->getMulExpr(StepSCEV, ScaleSCEV))

diff  --git a/llvm/test/Transforms/LoopReroll/basic.ll b/llvm/test/Transforms/LoopReroll/basic.ll
index 9eaadfb150ad3..c49dc9e364c96 100644
--- a/llvm/test/Transforms/LoopReroll/basic.ll
+++ b/llvm/test/Transforms/LoopReroll/basic.ll
@@ -810,6 +810,27 @@ for.end:                                          ; preds = %for.body
   ret void
 }
 
+ at a = external global [2 x [512 x i64]], align 16
+ at b = external global [512 x [4 x i64]], align 16
+
+define void @ptr_step_crash() {
+; CHECK-LABEL: @ptr_step_crash(
+entry:
+  br label %for.body42.3
+
+for.body42.3:                                     ; preds = %for.body42.3, %entry
+  %k.2207.3 = phi i32 [ -512, %entry ], [ %inc63.3, %for.body42.3 ]
+  %sub46.3 = add nsw i32 %k.2207.3, 512
+  %idxprom47.3 = zext i32 %sub46.3 to i64
+  %arrayidx48.3 = getelementptr inbounds [2 x [512 x i64]], [2 x [512 x i64]]* @a, i64 0, i64 0, i64 %idxprom47.3
+  %arrayidx55.3 = getelementptr inbounds [512 x [4 x i64]], [512 x [4 x i64]]* @b, i64 0, i64 %idxprom47.3, i64 3
+  %0 = load i64, i64* %arrayidx55.3, align 8
+  %inc63.3 = add nsw i32 %k.2207.3, 1
+  br i1 undef, label %for.inc65.3, label %for.body42.3
+
+for.inc65.3:                                      ; preds = %for.body42.3
+  ret void
+}
+
 attributes #0 = { nounwind uwtable }
 attributes #1 = { nounwind }
-


        


More information about the llvm-commits mailing list