[llvm] VT: teach a special-case optz about samesign (PR #122590)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 11 02:25:12 PST 2025


================
@@ -9495,7 +9495,8 @@ isImpliedCondICmps(const ICmpInst *LHS, CmpPredicate RPred, const Value *R0,
   // 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) &&
+  if ((ICmpInst::isSigned(LPred) || LPred.hasSameSign()) &&
----------------
dtcxzyw wrote:

I would expect a helper function `bool CmpPredicate::match(CmpInst::Predicate P) const` to check whether we can refine the predicate into P.

`bool operator==(CmpInst::Predicate P)` only checks the underlying predicate.
`bool CmpPredicate::match(CmpInst::Predicate P) const` takes both the underlying predicate and `samesign` flag into account.

An alternative is to add some helpers called `getSignedPred/getUnsignedPred`.


https://github.com/llvm/llvm-project/pull/122590


More information about the llvm-commits mailing list