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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun May 5 22:01:51 PDT 2024


================
@@ -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)) {
----------------
dtcxzyw wrote:

It is not a NFC. Please add some proofs and tests for this.

See https://github.com/llvm/llvm-project/blob/db0ed5533368414b1c4e1c884eef651c66359da2/llvm/lib/Analysis/ValueTracking.cpp#L6541-L6604

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


More information about the llvm-commits mailing list