[llvm] [InstCombineCompares] Try to "strengthen" compares based on known bits. (PR #79405)
Mikhail Gudim via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 20:00:06 PST 2024
================
@@ -6100,6 +6100,95 @@ bool InstCombinerImpl::replacedSelectWithOperand(SelectInst *SI,
return false;
}
+// Try to "strengthen" the RHS of compare based on known bits.
+// For example, replace `icmp ugt %x, 14` with `icmp ugt %x, 15` when
+// it is known that the two least significant bits of `%x` is zero.
+static Instruction *strengthenICmpUsingKnownBits(ICmpInst &I,
+ KnownBits Op0Known,
+ KnownBits Op1Known,
+ unsigned BitWidth) {
+ if (!BitWidth)
+ return nullptr;
+ if (!(Op1Known.isConstant() && Op0Known.Zero.isMask()))
+ return nullptr;
+
+ Value *Op0 = I.getOperand(0);
+ ICmpInst::Predicate Pred = I.getPredicate();
+ Type *Ty = Op0->getType();
+ APInt RHSConst = Op1Known.getConstant();
+ bool TrueIfSigned = false;
+ // Don't break the SignBitCheck pattern;
+ if (InstCombiner::isSignBitCheck(Pred, RHSConst, TrueIfSigned))
+ return nullptr;
+
----------------
mgudim wrote:
@dtcxzyw I just added test for select patterns and sign-check pattern. Everything works as intended. I tried your specific example and the pattern's wasn't broken. There must be something else happening in that code. Can you double check
that the degradation is still there? If yes, can you provide the reduced test case?
https://github.com/llvm/llvm-project/pull/79405
More information about the llvm-commits
mailing list