[llvm] [NFC] Prefer isSafeToSpeculativelyExecute to div/rem (PR #91157)

via llvm-commits llvm-commits at lists.llvm.org
Sun May 5 18:38:18 PDT 2024


https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/91157

>From 54a8024214b3e7eff08c394eaa616673305b6edd Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Sun, 5 May 2024 21:04:29 -0400
Subject: [PATCH] [InstCombine][NFC] Prefer isSafeToSpeculativelyExecute to
 div/rem

---
 llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 8818369e79452b..167043b6b4d19f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3800,11 +3800,10 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
   // Try to simplify a binop sandwiched between 2 selects with the same
   // condition. This is not valid for div/rem because the select might be
   // preventing a division-by-zero.
-  // TODO: A div/rem restriction is conservative; use something like
-  //       isSafeToSpeculativelyExecute().
   // select(C, binop(select(C, X, Y), W), Z) -> select(C, binop(X, W), Z)
   BinaryOperator *TrueBO;
-  if (match(TrueVal, m_OneUse(m_BinOp(TrueBO))) && !TrueBO->isIntDivRem()) {
+  if (match(TrueVal, m_OneUse(m_BinOp(TrueBO))) &&
+      isSafeToSpeculativelyExecute(TrueBO)) {
     if (auto *TrueBOSI = dyn_cast<SelectInst>(TrueBO->getOperand(0))) {
       if (TrueBOSI->getCondition() == CondVal) {
         replaceOperand(*TrueBO, 0, TrueBOSI->getTrueValue());



More information about the llvm-commits mailing list