[llvm] [SimplifyCFG] Deduce paths unreachable if they cause div/rem UB (PR #109008)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 11:22:44 PDT 2024


================
@@ -7882,6 +7882,14 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValu
       case Instruction::CallBr:
       case Instruction::Invoke:
         return true;
+      case Instruction::UDiv:
+      case Instruction::URem:
+        // Note: signed div/rem of INT_MIN / -1 is also immediate UB, not
+        // implemented to avoid code complexity as it is unclear how useful such
+        // logic is.
+      case Instruction::SDiv:
+      case Instruction::SRem:
+        return C->isNullValue();
----------------
nikic wrote:

As undef is chosen per-use, we can always chose zero here, even if another use is non-zero.

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


More information about the llvm-commits mailing list