[llvm] [InstCombine] Fold `(x < y) ? -1 : zext(x != y)` into `u/scmp(x,y)` (PR #101049)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 29 11:47:25 PDT 2024
================
@@ -3529,6 +3529,38 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) {
Masked);
}
+// This function tries to fold the following sequence
+// %lt = icmp ult/slt i32 %x, %y
+// %ne0 = icmp ne i32 %x, %y
+// %ne = zext i1 %ne0 to iN
+// %r = select i1 %lt, iN -1, iN %ne
+// into
+// %r = call iN @llvm.ucmp/scmp(%x, %y)
+Instruction *InstCombinerImpl::foldSelectToCmp(SelectInst &SI) {
+ if (!isa<Constant>(SI.getTrueValue()) ||
+ !dyn_cast<Constant>(SI.getTrueValue())->isAllOnesValue())
+ return nullptr;
+
+ Value *LHS, *RHS;
+ ICmpInst::Predicate NEPred;
+ if (!match(SI.getFalseValue(),
+ m_ZExt(m_ICmp(NEPred, m_Value(LHS), m_Value(RHS)))) ||
+ NEPred != ICmpInst::ICMP_NE)
----------------
dtcxzyw wrote:
```suggestion
m_ZExt(m_SpecificICmp(ICmpInst::ICMP_NE, m_Value(LHS), m_Value(RHS)))))
```
https://github.com/llvm/llvm-project/pull/101049
More information about the llvm-commits
mailing list