[llvm] [NFC] Prefer isSafeToSpeculativelyExecute to div/rem (PR #91157)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 5 18:31:11 PDT 2024
https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/91157
>From 115e006b584e0d44f1b40697c198900cb4449d35 Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Sun, 5 May 2024 21:04:29 -0400
Subject: [PATCH] Prefer isSafeToSpeculativelyExecute to div/rem
---
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 8818369e79452b..fa768554159f43 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3800,11 +3800,9 @@ 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