[llvm] [CodeGenPrepare] don't promote sdiv/srem by -1 (PR #218737)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 00:11:29 PDT 2026
================
@@ -8367,16 +8367,13 @@ class VectorPromoteHelper {
/// Check if it is profitable to promote \p ToBePromoted
/// by moving downward the transition through.
bool shouldPromote(const Instruction *ToBePromoted) const {
+ if (!isSafeToSpeculativelyExecuteWithVariableReplaced(ToBePromoted))
+ return false;
// Promote only if all the operands can be statically expanded.
// Indeed, we do not want to introduce any new kind of transitions.
for (const Use &U : ToBePromoted->operands()) {
const Value *Val = U.get();
if (Val == getEndOfTransition()) {
- // If the use is a division and the transition is on the rhs,
- // we cannot promote the operation, otherwise we may create a
- // division by zero.
- if (canCauseUndefinedBehavior(ToBePromoted, U.getOperandNo()))
----------------
im-lunex wrote:
https://github.com/llvm/llvm-project/blob/58e77af2bbdd95632a03787737627dda52e9cf07/llvm/lib/CodeGen/CodeGenPrepare.cpp#L8507-L8510
Here I tried using `isSafeToSpeculativelyExecuteWithVariableReplaced()` but since it only checks if the divisor is a 0 and has no concept of vector `poison`, it caused issues in this specific case. Instead, using `(U.getOperandNo() == 1 && ToBePromoted->isIntDivRem())` just prevents crash where it is needed .. this might change the behavior a bit .. i think this change should be okay.
https://github.com/llvm/llvm-project/pull/218737
More information about the llvm-commits
mailing list