aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorzhongyunde 00443407 <zhongyunde@huawei.com>2023-09-18 05:07:53 -0400
committerZhongyunde <zhongyunde@huawei.com>2024-08-06 10:30:03 +0800
commit30237130145d33be18ffa85b2145110c09d6cb1f (patch)
treedcbca78e7064d2ea912d2fe75ddd1a97ab28297a /llvm/lib/Analysis/ValueTracking.cpp
parentc41da1457051f239b153b798017938ce8e3d2405 (diff)
downloadllvm-30237130145d33be18ffa85b2145110c09d6cb1f.zip
llvm-30237130145d33be18ffa85b2145110c09d6cb1f.tar.gz
llvm-30237130145d33be18ffa85b2145110c09d6cb1f.tar.bz2
[ValueTracking] Infer relationship for the select with ICmp
x -nsw y < -C is false when x > y and C >= 0 Alive2 proof for sgt, sge : https://alive2.llvm.org/ce/z/tupvfi Note: It only really makes sense in the context of signed comparison for "X - Y must be positive if X >= Y and no overflow". Fixes https://github.com/llvm/llvm-project/issues/54735
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 2b7611c..ed81c05 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -9108,6 +9108,17 @@ static std::optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
if (L0 == R0 && L1 == R1)
return isImpliedCondMatchingOperands(LPred, RPred);
+ // It only really makes sense in the context of signed comparison for "X - Y
+ // must be positive if X >= Y and no overflow".
+ // Take SGT as an example: L0:x > L1:y and C >= 0
+ // ==> R0:(x -nsw y) < R1:(-C) is false
+ if ((LPred == ICmpInst::ICMP_SGT || LPred == ICmpInst::ICMP_SGE) &&
+ match(R0, m_NSWSub(m_Specific(L0), m_Specific(L1)))) {
+ if (match(R1, m_NonPositive()) &&
+ isImpliedCondMatchingOperands(LPred, RPred) == false)
+ return false;
+ }
+
// L0 = R0 = L1 + R1, L0 >=u L1 implies R0 >=u R1, L0 <u L1 implies R0 <u R1
if (L0 == R0 &&
(LPred == ICmpInst::ICMP_ULT || LPred == ICmpInst::ICMP_UGE) &&