[llvm] 0e465c0 - [IRCE] Bail in case of pointer types. PR40539
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 12 02:04:01 PDT 2022
Author: Max Kazantsev
Date: 2022-09-12T16:01:25+07:00
New Revision: 0e465c0c2f898f4fa730207c342459918d44e5e3
URL: https://github.com/llvm/llvm-project/commit/0e465c0c2f898f4fa730207c342459918d44e5e3
DIFF: https://github.com/llvm/llvm-project/commit/0e465c0c2f898f4fa730207c342459918d44e5e3.diff
LOG: [IRCE] Bail in case of pointer types. PR40539
We should not unconditionally expect that SCEVable types are all integers
because SCEV can also be computed for pointers. Bail in this case.
Added:
llvm/test/Transforms/IRCE/pr40539.ll
Modified:
llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
index 9d18f32a5960c..e429aafc896ed 100644
--- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -1583,8 +1583,11 @@ InductiveRangeCheck::computeSafeIterationSpace(
bool IsLatchSigned) const {
// We can deal when types of latch check and range checks don't match in case
// if latch check is more narrow.
- auto *IVType = cast<IntegerType>(IndVar->getType());
- auto *RCType = cast<IntegerType>(getBegin()->getType());
+ auto *IVType = dyn_cast<IntegerType>(IndVar->getType());
+ auto *RCType = dyn_cast<IntegerType>(getBegin()->getType());
+ // Do not work with pointer types.
+ if (!IVType || !RCType)
+ return None;
if (IVType->getBitWidth() > RCType->getBitWidth())
return None;
// IndVar is of the form "A + B * I" (where "I" is the canonical induction
diff --git a/llvm/test/Transforms/IRCE/pr40539.ll b/llvm/test/Transforms/IRCE/pr40539.ll
new file mode 100644
index 0000000000000..a8d6a37fa7dd2
--- /dev/null
+++ b/llvm/test/Transforms/IRCE/pr40539.ll
@@ -0,0 +1,47 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -irce -S < %s | FileCheck %s
+; RUN: opt -passes='require<branch-prob>,irce' -S < %s | FileCheck %s
+
+ at array = external global [1528 x i16], align 1
+
+; Make sure we do not crash here.
+define void @test_01() {
+; CHECK-LABEL: @test_01(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[CONT48:%.*]]
+; CHECK: cont48:
+; CHECK-NEXT: [[A2_0121:%.*]] = phi i16* [ [[ADD_PTR74:%.*]], [[CONT76:%.*]] ], [ getelementptr inbounds ([1528 x i16], [1528 x i16]* @array, i16 0, i16 0), [[ENTRY:%.*]] ]
+; CHECK-NEXT: [[I41_0119:%.*]] = phi i16 [ [[ADD73:%.*]], [[CONT76]] ], [ 0, [[ENTRY]] ]
+; CHECK-NEXT: [[ADD73]] = add nuw nsw i16 [[I41_0119]], 2
+; CHECK-NEXT: [[ADD_PTR74]] = getelementptr inbounds i16, i16* [[A2_0121]], i16 2
+; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i16* [[A2_0121]], inttoptr (i16 -2 to i16*)
+; CHECK-NEXT: br i1 [[TMP0]], label [[CONT76]], label [[HANDLER_POINTER_OVERFLOW75:%.*]]
+; CHECK: handler.pointer_overflow75:
+; CHECK-NEXT: unreachable
+; CHECK: cont76:
+; CHECK-NEXT: [[CMP43:%.*]] = icmp ult i16 [[ADD73]], 16
+; CHECK-NEXT: br i1 [[CMP43]], label [[CONT48]], label [[FOR_END77:%.*]]
+; CHECK: for.end77:
+; CHECK-NEXT: unreachable
+;
+entry:
+ br label %cont48
+
+cont48: ; preds = %cont76, %entry
+ %a2.0121 = phi i16* [ %add.ptr74, %cont76 ], [ getelementptr inbounds ([1528 x i16], [1528 x i16]* @array, i16 0, i16 0), %entry ]
+ %i41.0119 = phi i16 [ %add73, %cont76 ], [ 0, %entry ]
+ %add73 = add nuw nsw i16 %i41.0119, 2
+ %add.ptr74 = getelementptr inbounds i16, i16* %a2.0121, i16 2
+ %0 = icmp ult i16* %a2.0121, inttoptr (i16 -2 to i16*)
+ br i1 %0, label %cont76, label %handler.pointer_overflow75
+
+handler.pointer_overflow75: ; preds = %cont48
+ unreachable
+
+cont76: ; preds = %cont48
+ %cmp43 = icmp ult i16 %add73, 16
+ br i1 %cmp43, label %cont48, label %for.end77
+
+for.end77: ; preds = %cont76
+ unreachable
+}
More information about the llvm-commits
mailing list