[llvm] [SLP] Support FAdd/FSub as interchangeable instructions (PR #208002)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 06:37:41 PDT 2026
================
@@ -1050,34 +1051,42 @@ class BinOpSameOpcodeHelper {
AndBIT = 1 << 5,
OrBIT = 1 << 6,
XorBIT = 1 << 7,
- MainOpBIT = 1 << 8,
+ FAddBIT = 1 << 8,
+ FSubBIT = 1 << 9,
+ MainOpBIT = 1 << 10,
LLVM_MARK_AS_BITMASK_ENUM(MainOpBIT)
};
- /// Return a non-nullptr if either operand of I is a ConstantInt.
+ /// Return a non-nullptr if either operand of I is a ConstantInt (for the
+ /// integer opcodes) or a ConstantFP (for FAdd/FSub).
/// The second return value represents the operand position. We check the
- /// right-hand side first (1). If the right hand side is not a ConstantInt and
- /// the instruction is neither Sub, Shl, nor AShr, we then check the left hand
- /// side (0).
- static std::pair<ConstantInt *, unsigned>
+ /// right-hand side first (1). If the right hand side is not a constant and
+ /// the instruction is neither Sub, FSub, Shl, nor AShr, we then check the
+ /// left hand side (0).
+ static std::pair<Constant *, unsigned>
isBinOpWithConstantInt(const Instruction *I) {
unsigned Opcode = I->getOpcode();
assert(binary_search(SupportedOp, Opcode) && "Unsupported opcode.");
(void)SupportedOp;
auto *BinOp = cast<BinaryOperator>(I);
- if (auto *CI = dyn_cast<ConstantInt>(BinOp->getOperand(1)))
- return {CI, 1};
- if (Opcode == Instruction::Sub || Opcode == Instruction::Shl ||
- Opcode == Instruction::AShr)
+ auto GetConstant = [](Value *V) -> Constant * {
+ if (auto *CI = dyn_cast<ConstantInt>(V))
+ return CI;
+ return dyn_cast<ConstantFP>(V);
+ };
+ if (Constant *C = GetConstant(BinOp->getOperand(1)))
+ return {C, 1};
+ if (Opcode == Instruction::Sub || Opcode == Instruction::FSub ||
+ Opcode == Instruction::Shl || Opcode == Instruction::AShr)
----------------
alexey-bataev wrote:
Fixed
https://github.com/llvm/llvm-project/pull/208002
More information about the llvm-commits
mailing list