[llvm] 3bbd380 - [Reassociate][NFC] Use an appropriate dyn_cast for BinaryOperator
Warren Ristow via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 25 10:25:56 PDT 2022
Author: Warren Ristow
Date: 2022-07-25T10:24:43-07:00
New Revision: 3bbd380a5b51db23e829f8ce6b948e7b9d451f15
URL: https://github.com/llvm/llvm-project/commit/3bbd380a5b51db23e829f8ce6b948e7b9d451f15
DIFF: https://github.com/llvm/llvm-project/commit/3bbd380a5b51db23e829f8ce6b948e7b9d451f15.diff
LOG: [Reassociate][NFC] Use an appropriate dyn_cast for BinaryOperator
In D129523, it was noted that there is are some questionable naked casts
from Instruction to BinaryOperator, which could be addressed by doing a
dyn_cast directly to BinaryOperator, avoiding the need for the later cast.
This cleans up that casting.
Reviewed By: nikic, spatel, RKSimon
Differential Revision: https://reviews.llvm.org/D130448
Added:
Modified:
llvm/lib/Transforms/Scalar/Reassociate.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 53575f55c6fbd..cd2ce8ce336e5 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -154,20 +154,20 @@ static bool hasFPAssociativeFlags(Instruction *I) {
/// Return true if V is an instruction of the specified opcode and if it
/// only has one use.
static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) {
- auto *I = dyn_cast<Instruction>(V);
- if (I && I->hasOneUse() && I->getOpcode() == Opcode)
- if (!isa<FPMathOperator>(I) || hasFPAssociativeFlags(I))
- return cast<BinaryOperator>(I);
+ auto *BO = dyn_cast<BinaryOperator>(V);
+ if (BO && BO->hasOneUse() && BO->getOpcode() == Opcode)
+ if (!isa<FPMathOperator>(BO) || hasFPAssociativeFlags(BO))
+ return BO;
return nullptr;
}
static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode1,
unsigned Opcode2) {
- auto *I = dyn_cast<Instruction>(V);
- if (I && I->hasOneUse() &&
- (I->getOpcode() == Opcode1 || I->getOpcode() == Opcode2))
- if (!isa<FPMathOperator>(I) || hasFPAssociativeFlags(I))
- return cast<BinaryOperator>(I);
+ auto *BO = dyn_cast<BinaryOperator>(V);
+ if (BO && BO->hasOneUse() &&
+ (BO->getOpcode() == Opcode1 || BO->getOpcode() == Opcode2))
+ if (!isa<FPMathOperator>(BO) || hasFPAssociativeFlags(BO))
+ return BO;
return nullptr;
}
More information about the llvm-commits
mailing list