[llvm] [InstCombine] Make `(binop ({s|u}itofp),({s|u}itofp))` transform more flexible to mismatched signs (PR #84389)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 8 13:02:29 PST 2024
================
@@ -1406,57 +1406,48 @@ Value *InstCombinerImpl::dyn_castNegVal(Value *V) const {
// -> ({s|u}itofp (int_binop x, y))
// 2) (fp_binop ({s|u}itofp x), FpC)
// -> ({s|u}itofp (int_binop x, (fpto{s|u}i FpC)))
-Instruction *InstCombinerImpl::foldFBinOpOfIntCasts(BinaryOperator &BO) {
- Value *IntOps[2] = {nullptr, nullptr};
- Constant *Op1FpC = nullptr;
-
- // Check for:
- // 1) (binop ({s|u}itofp x), ({s|u}itofp y))
- // 2) (binop ({s|u}itofp x), FpC)
- if (!match(BO.getOperand(0), m_SIToFP(m_Value(IntOps[0]))) &&
- !match(BO.getOperand(0), m_UIToFP(m_Value(IntOps[0]))))
- return nullptr;
-
- if (!match(BO.getOperand(1), m_Constant(Op1FpC)) &&
- !match(BO.getOperand(1), m_SIToFP(m_Value(IntOps[1]))) &&
- !match(BO.getOperand(1), m_UIToFP(m_Value(IntOps[1]))))
- return nullptr;
+//
+// Assuming the sign of the cast for x/y is `OpsFromSigned`.
+Instruction *InstCombinerImpl::foldFBinOpOfIntCastsFromSign(
+ BinaryOperator &BO, bool OpsFromSigned, SmallVector<Value *, 2> IntOps,
+ Constant *Op1FpC, SmallVectorImpl<WithCache<const Value *>> *OpsKnown) {
----------------
nikic wrote:
Definitely prefer the reference. Also, why is this passing IntOps by value?
You might also want to replace the `SmallVector<Value *, 2>` with `std::array<Value *, 2>` here.
https://github.com/llvm/llvm-project/pull/84389
More information about the llvm-commits
mailing list