[llvm] [InstCombine] simplify `icmp pred x, ~x` (PR #73990)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 22 06:33:45 PDT 2024
================
@@ -4605,6 +4605,30 @@ static Instruction *foldICmpXorXX(ICmpInst &I, const SimplifyQuery &Q,
isKnownNonZero(A, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
return new ICmpInst(PredOut, Op0, Op1);
+ // These transform works when C is negative.
+ // X s< X^C, X s<= X^C, X u> X^C, X u>= X^C --> X s< 0
+ // X s> X^C, X s>= X^C, X u< X^C, X u<= X^C --> X s>= 0
+ if (auto C = dyn_cast<Constant>(A)) {
+ if (!C->getUniqueInteger().isNegative())
+ return nullptr;
----------------
nikic wrote:
This should use `m_Negative()` instead. getUniqueInteger() will assert on non-splat integer. Should have one test case for this.
https://github.com/llvm/llvm-project/pull/73990
More information about the llvm-commits
mailing list