Fix #56038
Diff Detail
Diff Detail
Event Timeline
Comment Actions
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().
Comment Actions
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; }
Comment Actions
@bcl5980 Conceptually, yes., but I believe your specific patch does not handle sdiv (i64 EXPR, i64 -1) correctly. We also only need this for the signed case.
Comment Actions
@nikic, Thanks for the explain. As I have little knowledge for this part can you help to fix the issue? I will abandon this change. Sorry for the disturbance.