[llvm] r328498 - [InstCombine] check uses before creating instructions for fmul distribution

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 26 07:25:44 PDT 2018


Author: spatel
Date: Mon Mar 26 07:25:43 2018
New Revision: 328498

URL: http://llvm.org/viewvc/llvm-project?rev=328498&view=rev
Log:
[InstCombine] check uses before creating instructions for fmul distribution

As the tests show, we could create extra instructions without any obvious benefit.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    llvm/trunk/test/Transforms/InstCombine/fmul.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=328498&r1=328497&r2=328498&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Mon Mar 26 07:25:43 2018
@@ -581,7 +581,7 @@ Instruction *InstCombiner::visitFMul(Bin
     // X * C, C/X, X/C, where C is a constant.
     // (MDC +/- C1) * C => (MDC * C) +/- (C1 * C)
     Instruction *FAddSub = dyn_cast<Instruction>(Op0);
-    if (FAddSub &&
+    if (FAddSub && FAddSub->hasOneUse() &&
         (FAddSub->getOpcode() == Instruction::FAdd ||
          FAddSub->getOpcode() == Instruction::FSub)) {
       Value *Opnd0 = FAddSub->getOperand(0);

Modified: llvm/trunk/test/Transforms/InstCombine/fmul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fmul.ll?rev=328498&r1=328497&r2=328498&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fmul.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fmul.ll Mon Mar 26 07:25:43 2018
@@ -495,14 +495,11 @@ define float @fmul_fadd_fmul_distribute(
   ret float %t3
 }
 
-; FIXME: More instructions than we started with.
-
 define float @fmul_fadd_distribute_extra_use(float %x) {
 ; CHECK-LABEL: @fmul_fadd_distribute_extra_use(
 ; CHECK-NEXT:    [[T1:%.*]] = fmul float [[X:%.*]], 6.000000e+00
 ; CHECK-NEXT:    [[T2:%.*]] = fadd float [[T1]], 2.000000e+00
-; CHECK-NEXT:    [[TMP1:%.*]] = fmul fast float [[X]], 3.000000e+01
-; CHECK-NEXT:    [[T3:%.*]] = fadd fast float [[TMP1]], 1.000000e+01
+; CHECK-NEXT:    [[T3:%.*]] = fmul fast float [[T2]], 5.000000e+00
 ; CHECK-NEXT:    call void @use_f32(float [[T2]])
 ; CHECK-NEXT:    ret float [[T3]]
 ;
@@ -559,14 +556,11 @@ define float @fmul_fsub_fmul_distribute(
   ret float %t3
 }
 
-; FIXME: More instructions than we started with.
-
 define float @fmul_fsub_fmul_distribute_extra_use(float %x) {
 ; CHECK-LABEL: @fmul_fsub_fmul_distribute_extra_use(
 ; CHECK-NEXT:    [[T1:%.*]] = fmul float [[X:%.*]], 6.000000e+00
 ; CHECK-NEXT:    [[T2:%.*]] = fsub float 2.000000e+00, [[T1]]
-; CHECK-NEXT:    [[TMP1:%.*]] = fmul fast float [[X]], 3.000000e+01
-; CHECK-NEXT:    [[T3:%.*]] = fsub fast float 1.000000e+01, [[TMP1]]
+; CHECK-NEXT:    [[T3:%.*]] = fmul fast float [[T2]], 5.000000e+00
 ; CHECK-NEXT:    call void @use_f32(float [[T2]])
 ; CHECK-NEXT:    ret float [[T3]]
 ;
@@ -591,14 +585,11 @@ define float @fmul_fsub_fmul_distribute2
   ret float %t3
 }
 
-; FIXME: More instructions than we started with.
-
 define float @fmul_fsub_fmul_distribute2_extra_use(float %x) {
 ; CHECK-LABEL: @fmul_fsub_fmul_distribute2_extra_use(
 ; CHECK-NEXT:    [[T1:%.*]] = fmul float [[X:%.*]], 6.000000e+00
 ; CHECK-NEXT:    [[T2:%.*]] = fsub float 2.000000e+00, [[T1]]
-; CHECK-NEXT:    [[TMP1:%.*]] = fmul fast float [[X]], 3.000000e+01
-; CHECK-NEXT:    [[T3:%.*]] = fsub fast float 1.000000e+01, [[TMP1]]
+; CHECK-NEXT:    [[T3:%.*]] = fmul fast float [[T2]], 5.000000e+00
 ; CHECK-NEXT:    call void @use_f32(float [[T2]])
 ; CHECK-NEXT:    ret float [[T3]]
 ;




More information about the llvm-commits mailing list