[llvm] f1e8136 - [SCEV] Bail out if URem operand cannot be zero-extended.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 1 05:51:42 PST 2021


Author: Florian Hahn
Date: 2021-02-01T13:50:54Z
New Revision: f1e8136115ac86a633f670cd4d50cf41b71418d8

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

LOG: [SCEV] Bail out if URem operand cannot be zero-extended.

In some cases, LHS is larger than the target expression type. Bail out
in that case for now, to avoid crashing

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp
    llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 134d4d0fc8c5..ce97fa0edbe3 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -13164,6 +13164,11 @@ bool ScalarEvolution::matchURem(const SCEV *Expr, const SCEV *&LHS,
   if (const auto *ZExt = dyn_cast<SCEVZeroExtendExpr>(Expr))
     if (const auto *Trunc = dyn_cast<SCEVTruncateExpr>(ZExt->getOperand(0))) {
       LHS = Trunc->getOperand();
+      // Bail out if the type of the LHS is larger than the type of the
+      // expression for now.
+      if (getTypeSizeInBits(LHS->getType()) >
+          getTypeSizeInBits(Expr->getType()))
+        return false;
       if (LHS->getType() != Expr->getType())
         LHS = getZeroExtendExpr(LHS, Expr->getType());
       RHS = getConstant(APInt(getTypeSizeInBits(Expr->getType()), 1)

diff  --git a/llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll b/llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll
index ccd03c0db3d9..57049ed9cb20 100644
--- a/llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll
+++ b/llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll
@@ -54,4 +54,26 @@ exit:
   ret void
 }
 
+define void @test_trunc_operand_larger_than_urem_expr(i64 %N) {
+; CHECK-LABEL: @test_trunc_operand_larger_than_urem_expr
+; CHECK:       Loop %for.body: backedge-taken count is (-1 + %N)
+; CHECK-NEXT:  Loop %for.body: max backedge-taken count is -1
+; CHECK-NEXT:  Loop %for.body: Predicated backedge-taken count is (-1 + %N)
+;
+entry:
+  %conv = trunc i64 %N to i32
+  %and = and i32 %conv, 1
+  %cmp.pre = icmp eq i32 %and, 0
+  br i1 %cmp.pre, label %for.body, label %exit
+
+for.body:
+  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
+  %iv.next = add nuw nsw i64 %iv, 1
+  %cmp.1 = icmp ne i64 %iv.next, %N
+  br i1 %cmp.1, label %for.body, label %exit
+
+exit:
+  ret void
+}
+
 declare void @llvm.assume(i1)


        


More information about the llvm-commits mailing list