[llvm] [InstCombine] Fold `ucmp/scmp(x, y) >> N` to `zext/sext(x < y)` when N is one less than the width of the result of `ucmp/scmp` (PR #104009)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 07:38:28 PDT 2024
================
@@ -511,6 +511,24 @@ Instruction *InstCombinerImpl::commonShiftTransforms(BinaryOperator &I) {
if (match(Op1, m_Or(m_Value(), m_SpecificInt(BitWidth - 1))))
return replaceOperand(I, 1, ConstantInt::get(Ty, BitWidth - 1));
+ Instruction *CmpIntr;
+ const APInt *ShiftAmount;
+ if ((I.getOpcode() == Instruction::LShr ||
+ I.getOpcode() == Instruction::AShr) &&
+ match(Op0, m_Instruction(CmpIntr)) && CmpIntr->hasOneUse() &&
+ isa<CmpIntrinsic>(CmpIntr) && match(Op1, m_APInt(ShiftAmount)) &&
+ *ShiftAmount + 1 == Ty->getIntegerBitWidth()) {
+ Value *Cmp = Builder.CreateICmp(
+ cast<CmpIntrinsic>(CmpIntr)->isSigned() ? ICmpInst::ICMP_SLT
+ : ICmpInst::ICMP_ULT,
----------------
nikic wrote:
Us `getLTPredicate()` instead?
https://github.com/llvm/llvm-project/pull/104009
More information about the llvm-commits
mailing list