[PATCH] D38288: [InstCombine] Restrict transforming shared selects using SimplifySelectsFeedingBinaryOp when we cannot simplify the binary op.

Balaram Makam via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 26 15:31:27 PDT 2017


bmakam created this revision.

We will still keep the original select if there are multiple uses thus increasing
the number of instructions, so enable this transform for shared selects only when
we can fold the binary op with a select.


https://reviews.llvm.org/D38288

Files:
  lib/Transforms/InstCombine/InstructionCombining.cpp
  test/Transforms/InstCombine/select_arithmetic.ll


Index: test/Transforms/InstCombine/select_arithmetic.ll
===================================================================
--- test/Transforms/InstCombine/select_arithmetic.ll
+++ test/Transforms/InstCombine/select_arithmetic.ll
@@ -38,3 +38,16 @@
 ; CHECK: ret float %tmp2
 }
 
+; Tests not folding constants if the selects have more than one use.
+declare void @use_double(double)
+define double @test4(i1 zeroext %arg, double %div) {
+  %tmp = select i1 %arg, double %div, double 5.000000e-03
+  %mul = fmul contract double %tmp, %tmp
+  call void @use_double(double %tmp)
+  ret double %mul
+; CHECK-LABEL: @test4(
+; CHECK: [[TMP:%.*]] = select i1 %arg, double %div, double 5.000000e-03
+; CHECK-NEXT: [[MUL:%.*]] = fmul contract double [[TMP]], [[TMP]]
+; CHECK-NOT: fmul contract double %div, %div
+; CHECK: ret double [[MUL]]
+}
Index: lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- lib/Transforms/InstCombine/InstructionCombining.cpp
+++ lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -729,8 +729,8 @@
   // c, e)))
   Value *A, *B, *C, *D, *E;
   Value *SI = nullptr;
-  if (match(LHS, m_Select(m_Value(A), m_Value(B), m_Value(C))) &&
-      match(RHS, m_Select(m_Specific(A), m_Value(D), m_Value(E)))) {
+  if (match(LHS, m_OneUse(m_Select(m_Value(A), m_Value(B), m_Value(C)))) &&
+      match(RHS, m_OneUse(m_Select(m_Specific(A), m_Value(D), m_Value(E))))) {
     BuilderTy::FastMathFlagGuard Guard(Builder);
     if (isa<FPMathOperator>(&I))
       Builder.setFastMathFlags(I.getFastMathFlags());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38288.116693.patch
Type: text/x-patch
Size: 1597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170926/8cc31edb/attachment-0001.bin>


More information about the llvm-commits mailing list