[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
This commit is contained in:
parent
fc93ba061a
commit
3bbd380a5b
|
@ -154,20 +154,20 @@ static bool hasFPAssociativeFlags(Instruction *I) {
|
||||||
/// Return true if V is an instruction of the specified opcode and if it
|
/// Return true if V is an instruction of the specified opcode and if it
|
||||||
/// only has one use.
|
/// only has one use.
|
||||||
static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) {
|
static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) {
|
||||||
auto *I = dyn_cast<Instruction>(V);
|
auto *BO = dyn_cast<BinaryOperator>(V);
|
||||||
if (I && I->hasOneUse() && I->getOpcode() == Opcode)
|
if (BO && BO->hasOneUse() && BO->getOpcode() == Opcode)
|
||||||
if (!isa<FPMathOperator>(I) || hasFPAssociativeFlags(I))
|
if (!isa<FPMathOperator>(BO) || hasFPAssociativeFlags(BO))
|
||||||
return cast<BinaryOperator>(I);
|
return BO;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode1,
|
static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode1,
|
||||||
unsigned Opcode2) {
|
unsigned Opcode2) {
|
||||||
auto *I = dyn_cast<Instruction>(V);
|
auto *BO = dyn_cast<BinaryOperator>(V);
|
||||||
if (I && I->hasOneUse() &&
|
if (BO && BO->hasOneUse() &&
|
||||||
(I->getOpcode() == Opcode1 || I->getOpcode() == Opcode2))
|
(BO->getOpcode() == Opcode1 || BO->getOpcode() == Opcode2))
|
||||||
if (!isa<FPMathOperator>(I) || hasFPAssociativeFlags(I))
|
if (!isa<FPMathOperator>(BO) || hasFPAssociativeFlags(BO))
|
||||||
return cast<BinaryOperator>(I);
|
return BO;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue