[PATCH] D155255: [SCEV] Don't update the range value if empty
Davide Italiano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 13 18:26:46 PDT 2023
davide created this revision.
davide added reviewers: nikic, aeubanks, aemerson, fhahn.
Herald added subscribers: StephenFan, javed.absar, hiraditya.
Herald added a project: All.
davide requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The recent commit 22ca38da25e19a7c5fcfeb3f22159aba92ec381e <https://reviews.llvm.org/rG22ca38da25e19a7c5fcfeb3f22159aba92ec381e> introduces the ability to analyze ranges for heap allocations.
In some cases, like the one in the test, the range is empty as `ConstantRange` represents an half-open range on the upper side (in the very specific case, [1;1)). Detect this case, similarly to other ranges transformations in SCEV, rather than crashing.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155255
Files:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Transforms/LoopStrengthReduce/scev-operator-new.ll
Index: llvm/test/Transforms/LoopStrengthReduce/scev-operator-new.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopStrengthReduce/scev-operator-new.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -passes=loop-reduce -S | FileCheck %s
+
+; CHECK: define void @patatino() {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %for.cond9
+
+; CHECK: for.cond9:
+; CHECK-NEXT: br label %for.cond9
+; CHECK-NEXT:}
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @patatino() {
+entry:
+ %call443 = tail call nonnull ptr @_Znam(i64 -1)
+ br label %for.cond9
+
+for.cond9:
+ %lsr.iv = phi ptr [ %call443, %entry ], [ %scevgep, %for.cond9 ]
+ %scevgep = getelementptr i8, ptr %lsr.iv, i64 4
+ br label %for.cond9
+}
+
+declare ptr @_Znam(i64)
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6832,8 +6832,10 @@
APInt MinVal = APInt::getZero(BitWidth);
if (llvm::isKnownNonZero(V, DL))
MinVal = Align;
- ConservativeResult = ConservativeResult.intersectWith(
- {MinVal, MaxVal + 1}, RangeType);
+ if (MinVal != MaxVal + 1) {
+ ConservativeResult = ConservativeResult.intersectWith(
+ {MinVal, MaxVal + 1}, RangeType);
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155255.540246.patch
Type: text/x-patch
Size: 1482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230714/48da1ab9/attachment.bin>
More information about the llvm-commits
mailing list