[llvm] 2c7d5fb - [SCEV] Generalize implication when signedness of FoundPred doesn't matter
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 20 21:30:53 PDT 2021
Author: Max Kazantsev
Date: 2021-09-21T11:17:56+07:00
New Revision: 2c7d5fbc9ebf914f90acad8534289ea01e899ec8
URL: https://github.com/llvm/llvm-project/commit/2c7d5fbc9ebf914f90acad8534289ea01e899ec8
DIFF: https://github.com/llvm/llvm-project/commit/2c7d5fbc9ebf914f90acad8534289ea01e899ec8.diff
LOG: [SCEV] Generalize implication when signedness of FoundPred doesn't matter
The implication logic for two values that are both negative or non-negative
says that it doesn't matter whether their predicate is signed and unsigned,
but only flips unsigned into signed for further inference. This patch adds
support for flipping a signed predicate into unsigned as well.
Differential Revision: https://reviews.llvm.org/D109959
Reviewed By: nikic
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Transforms/IndVarSimplify/negative_ranges.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 1482a47158a76..b9a319474ed6c 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -10704,8 +10704,13 @@ bool ScalarEvolution::isImpliedCondBalancedTypes(
// 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);
diff --git a/llvm/test/Transforms/IndVarSimplify/negative_ranges.ll b/llvm/test/Transforms/IndVarSimplify/negative_ranges.ll
index 5db305ab68a16..67fd05465d3f7 100644
--- a/llvm/test/Transforms/IndVarSimplify/negative_ranges.ll
+++ b/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 @@ define i32 @test_01(i32* %p, i32* %s) {
; 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()
More information about the llvm-commits
mailing list