[llvm] [CodeGenPrepare] don't promote sdiv/srem by -1 (PR #218737)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 00:13:08 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()))
----------------
nikic wrote:

Can you please leave this change out of this PR? I think it's best to change this code separately.

https://github.com/llvm/llvm-project/pull/218737


More information about the llvm-commits mailing list