[llvm] [llvm] Optimize usub.sat fix for #79690 (PR #151044)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 30 04:35:08 PDT 2025
================
@@ -1993,6 +1993,63 @@ Value *InstCombinerImpl::foldSelectWithConstOpToBinOp(ICmpInst *Cmp,
return BinOp;
}
+/// Folds:
+/// %a_sub = call @llvm.usub.sat(x, IntConst1)
+/// %b_sub = call @llvm.usub.sat(y, IntConst2)
+/// %or = or %a_sub, %b_sub
+/// %cmp = icmp eq %or, 0
+/// %sel = select %cmp, 0, MostSignificantBit
+/// into:
+/// %a_sub' = usub.sat(x, IntConst1 - MostSignificantBit)
+/// %b_sub' = usub.sat(y, IntConst2 - MostSignificantBit)
+/// %or = or %a_sub', %b_sub'
+/// %and = and %or, MostSignificantBit
+/// Likewise, for vector arguments as well.
+static Instruction *foldICmpUSubSatWithAndForMostSignificantBitCmp(
+ SelectInst &SI, ICmpInst *ICI, InstCombiner::BuilderTy &Builder) {
+ if (!SI.hasOneUse() || !ICI->hasOneUse())
+ return nullptr;
+ CmpPredicate Pred;
+ Value *A, *B;
+ const APInt *Constant1, *Constant2;
+ if (!match(SI.getCondition(),
+ m_ICmp(Pred,
+ m_Or(m_Intrinsic<Intrinsic::usub_sat>(m_Value(A),
----------------
dtcxzyw wrote:
Missing one-use check on `or` and `usub_sat`.
https://github.com/llvm/llvm-project/pull/151044
More information about the llvm-commits
mailing list