[llvm] [InstCombine] Missing optimization: fold mul (select a, b), (select b, a) to mul a, b (PR #74953)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 11 05:51:48 PST 2023


================
@@ -1132,6 +1132,15 @@ Value *InstCombinerImpl::SimplifySelectsFeedingBinaryOp(BinaryOperator &I,
   };
 
   if (LHSIsSelect && RHSIsSelect && A == D) {
+    // op(select(%v, %x, %y), select(%v, %y, %x)) --> op(%x, %y)
+    if (I.isCommutative() && B == F && C == E) {
+      Value *BI = Builder.CreateBinOp(I.getOpcode(), B, E);
+      if (auto *BO = dyn_cast<BinaryOperator>(BI))
+        BO->copyIRFlags(BI);
----------------
nikic wrote:

```suggestion
        BO->copyIRFlags(&I);
```
As written this copied the flags to itself...

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


More information about the llvm-commits mailing list