diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index 90b13ab1730..2a69c418934 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -143,20 +143,20 @@ XorOpnd::XorOpnd(Value *V) { /// 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) { - if (V->hasOneUse() && isa(V) && - cast(V)->getOpcode() == Opcode && - (!isa(V) || cast(V)->isFast())) - return cast(V); + auto *I = dyn_cast(V); + if (I && I->hasOneUse() && I->getOpcode() == Opcode) + if (!isa(I) || I->isFast()) + return cast(I); return nullptr; } static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode1, unsigned Opcode2) { - if (V->hasOneUse() && isa(V) && - (cast(V)->getOpcode() == Opcode1 || - cast(V)->getOpcode() == Opcode2) && - (!isa(V) || cast(V)->isFast())) - return cast(V); + auto *I = dyn_cast(V); + if (I && I->hasOneUse() && + (I->getOpcode() == Opcode1 || I->getOpcode() == Opcode2)) + if (!isa(I) || I->isFast()) + return cast(I); return nullptr; }