[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:52:22 PDT 2024


================
@@ -4201,5 +4201,23 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
     }
   }
 
+  // select (trunc nuw X to i1), X, Y --> select (trunc nuw X to i1), 1, Y
+  // select (trunc nuw X to i1), Y, X --> select (trunc nuw X to i1), Y, 0
+  // select (trunc nsw X to i1), X, Y --> select (trunc nsw X to i1), -1, Y
+  // select (trunc nsw X to i1), Y, X --> select (trunc nsw X to i1), Y, 0
+  Value *Trunc;
+  if (match(CondVal, m_NUWTrunc(m_Value(Trunc)))) {
+    if (match(TrueVal, m_Specific(Trunc)))
----------------
nikic wrote:

```suggestion
    if (TrueVal == Trunc)
```
etc.

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


More information about the llvm-commits mailing list