[PATCH] D127950: [SimplifyCFG] Check isSafeToSpeculativelyExecute before computeSpeculationCost
chenglin.bi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 16 05:24:48 PDT 2022
bcl5980 added a comment.
In D127950#3588529 <https://reviews.llvm.org/D127950#3588529>, @nikic wrote:
> I believe the real problem here is that canTrap() only checks for division by zero, but not division of SIGNED_MIN by -1, which also traps. This leads to an inconsistency between canTrap() and isSafeToSpeculativelyExecute().
Is this what you want to do ?
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -592,7 +592,10 @@ static bool canTrapImpl(const Constant *C,
case Instruction::URem:
case Instruction::SRem:
// Div and rem can trap if the RHS is not known to be non-zero.
- if (!isa<ConstantInt>(CE->getOperand(1)) ||CE->getOperand(1)->isNullValue())
+ if (!isa<ConstantInt>(CE->getOperand(1)) ||
+ CE->getOperand(1)->isNullValue() ||
+ (CE->getOperand(0)->isMinSignedValue() &&
+ CE->getOperand(1)->isAllOnesValue()))
return true;
return false;
}
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127950/new/
https://reviews.llvm.org/D127950
More information about the llvm-commits
mailing list