[llvm] 033d6ff - IR: Add operator | and & for FastMathFlags
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 28 16:26:00 PDT 2023
Author: Matt Arsenault
Date: 2023-08-28T19:25:54-04:00
New Revision: 033d6ffb53ad7897dd85b40114e4c3124f800e3e
URL: https://github.com/llvm/llvm-project/commit/033d6ffb53ad7897dd85b40114e4c3124f800e3e
DIFF: https://github.com/llvm/llvm-project/commit/033d6ffb53ad7897dd85b40114e4c3124f800e3e.diff
LOG: IR: Add operator | and & for FastMathFlags
We only had |= and &= which was annoying.
Added:
Modified:
llvm/include/llvm/IR/FMF.h
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/FMF.h b/llvm/include/llvm/IR/FMF.h
index 99e9a247777936..f063060567db21 100644
--- a/llvm/include/llvm/IR/FMF.h
+++ b/llvm/include/llvm/IR/FMF.h
@@ -110,6 +110,16 @@ class FastMathFlags {
void print(raw_ostream &O) const;
};
+inline FastMathFlags operator|(FastMathFlags LHS, FastMathFlags RHS) {
+ LHS |= RHS;
+ return LHS;
+}
+
+inline FastMathFlags operator&(FastMathFlags LHS, FastMathFlags RHS) {
+ LHS &= RHS;
+ return LHS;
+}
+
inline raw_ostream &operator<<(raw_ostream &O, FastMathFlags FMF) {
FMF.print(O);
return O;
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 3f14bb90e669dc..fbeabf607729e6 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -2591,9 +2591,7 @@ Instruction *InstCombinerImpl::hoistFNegAboveFMulFDiv(Value *FNegOp,
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(FNegOp)) {
// Make sure to preserve flags and metadata on the call.
if (II->getIntrinsicID() == Intrinsic::ldexp) {
- FastMathFlags FMF = FMFSource.getFastMathFlags();
- FMF |= II->getFastMathFlags();
-
+ FastMathFlags FMF = FMFSource.getFastMathFlags() | II->getFastMathFlags();
IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
Builder.setFastMathFlags(FMF);
@@ -2641,8 +2639,7 @@ Instruction *InstCombinerImpl::visitFNeg(UnaryOperator &I) {
auto propagateSelectFMF = [&](SelectInst *S, bool CommonOperand) {
S->copyFastMathFlags(&I);
if (auto *OldSel = dyn_cast<SelectInst>(Op)) {
- FastMathFlags FMF = I.getFastMathFlags();
- FMF |= OldSel->getFastMathFlags();
+ FastMathFlags FMF = I.getFastMathFlags() | OldSel->getFastMathFlags();
S->setFastMathFlags(FMF);
if (!OldSel->hasNoSignedZeros() && !CommonOperand &&
!isGuaranteedNotToBeUndefOrPoison(OldSel->getCondition()))
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 9f690fb74872d2..cf8c3a4a09d4df 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -544,10 +544,10 @@ bool InstCombinerImpl::SimplifyAssociativeOrCommutative(BinaryOperator &I) {
BinaryOperator::Create(Opcode, A, B);
if (isa<FPMathOperator>(NewBO)) {
- FastMathFlags Flags = I.getFastMathFlags();
- Flags &= Op0->getFastMathFlags();
- Flags &= Op1->getFastMathFlags();
- NewBO->setFastMathFlags(Flags);
+ FastMathFlags Flags = I.getFastMathFlags() &
+ Op0->getFastMathFlags() &
+ Op1->getFastMathFlags();
+ NewBO->setFastMathFlags(Flags);
}
InsertNewInstWith(NewBO, I);
NewBO->takeName(Op1);
More information about the llvm-commits
mailing list