[PATCH] D109959: [SCEV] Generalize implication when signedness of FoundPred doesn't matter
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 20 21:30:59 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2c7d5fbc9ebf: [SCEV] Generalize implication when signedness of FoundPred doesn't matter (authored by mkazantsev).
Changed prior to commit:
https://reviews.llvm.org/D109959?vs=373182&id=373779#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109959/new/
https://reviews.llvm.org/D109959
Files:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Transforms/IndVarSimplify/negative_ranges.ll
Index: llvm/test/Transforms/IndVarSimplify/negative_ranges.ll
===================================================================
--- llvm/test/Transforms/IndVarSimplify/negative_ranges.ll
+++ llvm/test/Transforms/IndVarSimplify/negative_ranges.ll
@@ -4,7 +4,6 @@
declare i1 @cond()
-; FIXME: 2nd check is implied by the 1st one as both values are negative.
define i32 @test_01(i32* %p, i32* %s) {
; CHECK-LABEL: @test_01(
; CHECK-NEXT: entry:
@@ -16,8 +15,7 @@
; CHECK-NEXT: [[C1:%.*]] = icmp slt i32 [[IV]], [[END]]
; CHECK-NEXT: br i1 [[C1]], label [[GUARDED:%.*]], label [[SIDE_EXIT:%.*]]
; CHECK: guarded:
-; CHECK-NEXT: [[C2:%.*]] = icmp ult i32 [[IV]], [[END]]
-; CHECK-NEXT: br i1 [[C2]], label [[BACKEDGE]], label [[SIDE_EXIT]]
+; CHECK-NEXT: br i1 true, label [[BACKEDGE]], label [[SIDE_EXIT]]
; CHECK: backedge:
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
; CHECK-NEXT: [[LOOP_COND:%.*]] = call i1 @cond()
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -10704,8 +10704,13 @@
// Unsigned comparison is the same as signed comparison when both the operands
// are non-negative or negative.
- if (CmpInst::isUnsigned(FoundPred) &&
- CmpInst::getSignedPredicate(FoundPred) == Pred &&
+ auto IsSignFlippedPredicate = [](CmpInst::Predicate P1,
+ CmpInst::Predicate P2) {
+ assert(P1 != P2 && "Handled earlier!");
+ return CmpInst::isRelational(P2) &&
+ P1 == CmpInst::getFlippedSignednessPredicate(P2);
+ };
+ if (IsSignFlippedPredicate(Pred, FoundPred) &&
((isKnownNonNegative(FoundLHS) && isKnownNonNegative(FoundRHS)) ||
(isKnownNegative(FoundLHS) && isKnownNegative(FoundRHS))))
return isImpliedCondOperands(Pred, LHS, RHS, FoundLHS, FoundRHS, CtxI);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109959.373779.patch
Type: text/x-patch
Size: 1957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210921/27030d5d/attachment.bin>
More information about the llvm-commits
mailing list