[llvm] [InstCombine] fold `select (trunc nuw X to i1), X, Y` to `select (trunc nuw X to i1), 1, Y` (PR #105914)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 24 00:17:01 PDT 2024


================
@@ -4201,5 +4201,15 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
     }
   }
 
+  // select (trunc nuw X to i1), X, Y --> select (trunc nuw X to i1), 1, Y
+  if (auto *TI = dyn_cast<TruncInst>(CondVal)) {
+    Value *Trunc;
+    if (TI->hasNoUnsignedWrap() && match(CondVal, m_Trunc(m_Value(Trunc))) &&
----------------
nikic wrote:

```suggestion
    if (match(CondVal, m_NUWTrunc(m_Value(Trunc))) &&
```

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


More information about the llvm-commits mailing list