[llvm] [IRBuilder] Fold binary intrinsics (PR #80743)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 22 05:20:30 PST 2024
================
@@ -14116,28 +14116,12 @@ class HorizontalReduction {
return Builder.CreateBinOp((Instruction::BinaryOps)RdxOpcode, LHS, RHS,
Name);
case RecurKind::FMax:
- if (IsConstant)
- return ConstantFP::get(LHS->getType(),
- maxnum(cast<ConstantFP>(LHS)->getValueAPF(),
- cast<ConstantFP>(RHS)->getValueAPF()));
return Builder.CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS);
case RecurKind::FMin:
- if (IsConstant)
- return ConstantFP::get(LHS->getType(),
- minnum(cast<ConstantFP>(LHS)->getValueAPF(),
- cast<ConstantFP>(RHS)->getValueAPF()));
return Builder.CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS);
case RecurKind::FMaximum:
- if (IsConstant)
- return ConstantFP::get(LHS->getType(),
- maximum(cast<ConstantFP>(LHS)->getValueAPF(),
- cast<ConstantFP>(RHS)->getValueAPF()));
return Builder.CreateBinaryIntrinsic(Intrinsic::maximum, LHS, RHS);
case RecurKind::FMinimum:
- if (IsConstant)
- return ConstantFP::get(LHS->getType(),
- minimum(cast<ConstantFP>(LHS)->getValueAPF(),
- cast<ConstantFP>(RHS)->getValueAPF()));
return Builder.CreateBinaryIntrinsic(Intrinsic::minimum, LHS, RHS);
----------------
RKSimon wrote:
You should now be able to merge these and use getMinMaxReductionIntrinsicOp(Kind) to get the Intrinsic::ID
```cpp
case RecurKind::FMax:
case RecurKind::FMin:
case RecurKind::FMaximum:
case RecurKind::FMinimum:
return Builder.CreateBinaryIntrinsic(getMinMaxReductionIntrinsicOp(Kind), LHS, RHS);
```
https://github.com/llvm/llvm-project/pull/80743
More information about the llvm-commits
mailing list