[Reassociate] don't name values "tmp"; NFCI

The toxic stew of created values named 'tmp' and tests that already have
values named 'tmp' and CHECK lines looking for values named 'tmp' causes
bad things to happen in our test line auto-generation scripts because it
wants to use 'TMP' as a prefix for unnamed values. Use less 'tmp' to 
avoid that.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317818 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjay Patel 2017-11-09 18:14:24 +00:00
parent d28baf6183
commit 114cb60a37
9 changed files with 281 additions and 255 deletions

View File

@ -997,7 +997,7 @@ static Value *EmitAddTreeOfValues(Instruction *I,
Value *V1 = Ops.back(); Value *V1 = Ops.back();
Ops.pop_back(); Ops.pop_back();
Value *V2 = EmitAddTreeOfValues(I, Ops); Value *V2 = EmitAddTreeOfValues(I, Ops);
return CreateAdd(V2, V1, "tmp", I, I); return CreateAdd(V2, V1, "reass.add", I, I);
} }
/// If V is an expression tree that is a multiplication sequence, /// If V is an expression tree that is a multiplication sequence,
@ -1604,7 +1604,7 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
RedoInsts.insert(VI); RedoInsts.insert(VI);
// Create the multiply. // Create the multiply.
Instruction *V2 = CreateMul(V, MaxOccVal, "tmp", I, I); Instruction *V2 = CreateMul(V, MaxOccVal, "reass.mul", I, I);
// Rerun associate on the multiply in case the inner expression turned into // Rerun associate on the multiply in case the inner expression turned into
// a multiply. We want to make sure that we keep things in canonical form. // a multiply. We want to make sure that we keep things in canonical form.

View File

@ -2,22 +2,22 @@
; With reassociation, constant folding can eliminate the 12 and -12 constants. ; With reassociation, constant folding can eliminate the 12 and -12 constants.
define float @test1(float %arg) { define float @test1(float %arg) {
; CHECK-LABEL: @test1 ; CHECK-LABEL: @test1(
; CHECK-NEXT: fsub fast float -0.000000e+00, %arg ; CHECK-NEXT: [[ARG_NEG:%.*]] = fsub fast float -0.000000e+00, %arg
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[ARG_NEG]]
;
%tmp1 = fsub fast float -1.200000e+01, %arg %t1 = fsub fast float -1.200000e+01, %arg
%tmp2 = fadd fast float %tmp1, 1.200000e+01 %t2 = fadd fast float %t1, 1.200000e+01
ret float %tmp2 ret float %t2
} }
define float @test2(float %reg109, float %reg1111) { define float @test2(float %reg109, float %reg1111) {
; CHECK-LABEL: @test2 ; CHECK-LABEL: @test2(
; CHECK-NEXT: fadd float %reg109, -3.000000e+01 ; CHECK-NEXT: [[REG115:%.*]] = fadd float %reg109, -3.000000e+01
; CHECK-NEXT: fadd float %reg115, %reg1111 ; CHECK-NEXT: [[REG116:%.*]] = fadd float [[REG115]], %reg1111
; CHECK-NEXT: fadd float %reg116, 3.000000e+01 ; CHECK-NEXT: [[REG117:%.*]] = fadd float [[REG116]], 3.000000e+01
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[REG117]]
;
%reg115 = fadd float %reg109, -3.000000e+01 %reg115 = fadd float %reg109, -3.000000e+01
%reg116 = fadd float %reg115, %reg1111 %reg116 = fadd float %reg115, %reg1111
%reg117 = fadd float %reg116, 3.000000e+01 %reg117 = fadd float %reg116, 3.000000e+01
@ -25,10 +25,10 @@ define float @test2(float %reg109, float %reg1111) {
} }
define float @test3(float %reg109, float %reg1111) { define float @test3(float %reg109, float %reg1111) {
; CHECK-LABEL: @test3 ; CHECK-LABEL: @test3(
; CHECK-NEXT: %reg117 = fadd fast float %reg109, %reg1111 ; CHECK-NEXT: [[REG117:%.*]] = fadd fast float %reg109, %reg1111
; CHECK-NEXT: ret float %reg117 ; CHECK-NEXT: ret float [[REG117]]
;
%reg115 = fadd fast float %reg109, -3.000000e+01 %reg115 = fadd fast float %reg109, -3.000000e+01
%reg116 = fadd fast float %reg115, %reg1111 %reg116 = fadd fast float %reg115, %reg1111
%reg117 = fadd fast float %reg116, 3.000000e+01 %reg117 = fadd fast float %reg116, 3.000000e+01
@ -42,12 +42,16 @@ define float @test3(float %reg109, float %reg1111) {
@ff = external global float @ff = external global float
define void @test4() { define void @test4() {
; CHECK-LABEL: @test4 ; CHECK-LABEL: @test4(
; CHECK: fadd fast float ; CHECK-NEXT: [[A:%.*]] = load float, float* @fa, align 4
; CHECK: fadd fast float ; CHECK-NEXT: [[B:%.*]] = load float, float* @fb, align 4
; CHECK-NOT: fadd fast float ; CHECK-NEXT: [[C:%.*]] = load float, float* @fc, align 4
; CHECK: ret void ; CHECK-NEXT: [[T1:%.*]] = fadd fast float [[B]], [[A]]
; CHECK-NEXT: [[T2:%.*]] = fadd fast float [[T1]], [[C]]
; CHECK-NEXT: store float [[T2]], float* @fe, align 4
; CHECK-NEXT: store float [[T2]], float* @ff, align 4
; CHECK-NEXT: ret void
;
%A = load float, float* @fa %A = load float, float* @fa
%B = load float, float* @fb %B = load float, float* @fb
%C = load float, float* @fc %C = load float, float* @fc
@ -63,12 +67,16 @@ define void @test4() {
} }
define void @test5() { define void @test5() {
; CHECK-LABEL: @test5 ; CHECK-LABEL: @test5(
; CHECK: fadd fast float ; CHECK-NEXT: [[A:%.*]] = load float, float* @fa, align 4
; CHECK: fadd fast float ; CHECK-NEXT: [[B:%.*]] = load float, float* @fb, align 4
; CHECK-NOT: fadd ; CHECK-NEXT: [[C:%.*]] = load float, float* @fc, align 4
; CHECK: ret void ; CHECK-NEXT: [[T1:%.*]] = fadd fast float [[B]], [[A]]
; CHECK-NEXT: [[T2:%.*]] = fadd fast float [[T1]], [[C]]
; CHECK-NEXT: store float [[T2]], float* @fe, align 4
; CHECK-NEXT: store float [[T2]], float* @ff, align 4
; CHECK-NEXT: ret void
;
%A = load float, float* @fa %A = load float, float* @fa
%B = load float, float* @fb %B = load float, float* @fb
%C = load float, float* @fc %C = load float, float* @fc
@ -84,12 +92,16 @@ define void @test5() {
} }
define void @test6() { define void @test6() {
; CHECK-LABEL: @test6 ; CHECK-LABEL: @test6(
; CHECK: fadd fast float ; CHECK-NEXT: [[A:%.*]] = load float, float* @fa, align 4
; CHECK: fadd fast float ; CHECK-NEXT: [[B:%.*]] = load float, float* @fb, align 4
; CHECK-NOT: fadd ; CHECK-NEXT: [[C:%.*]] = load float, float* @fc, align 4
; CHECK: ret void ; CHECK-NEXT: [[T1:%.*]] = fadd fast float [[B]], [[A]]
; CHECK-NEXT: [[T2:%.*]] = fadd fast float [[T1]], [[C]]
; CHECK-NEXT: store float [[T2]], float* @fe, align 4
; CHECK-NEXT: store float [[T2]], float* @ff, align 4
; CHECK-NEXT: ret void
;
%A = load float, float* @fa %A = load float, float* @fa
%B = load float, float* @fb %B = load float, float* @fb
%C = load float, float* @fc %C = load float, float* @fc
@ -105,12 +117,12 @@ define void @test6() {
} }
define float @test7(float %A, float %B, float %C) { define float @test7(float %A, float %B, float %C) {
; CHECK-LABEL: @test7 ; CHECK-LABEL: @test7(
; CHECK-NEXT: fadd fast float %C, %B ; CHECK-NEXT: [[REASS_ADD1:%.*]] = fadd fast float %C, %B
; CHECK-NEXT: fmul fast float %A, %A ; CHECK-NEXT: [[REASS_MUL2:%.*]] = fmul fast float %A, %A
; CHECK-NEXT: fmul fast float %tmp3, %tmp2 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_MUL:%.*]]2, [[REASS_ADD1]]
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[REASS_MUL]]
;
%aa = fmul fast float %A, %A %aa = fmul fast float %A, %A
%aab = fmul fast float %aa, %B %aab = fmul fast float %aa, %B
%ac = fmul fast float %A, %C %ac = fmul fast float %A, %C
@ -120,11 +132,11 @@ define float @test7(float %A, float %B, float %C) {
} }
define float @test8(float %X, float %Y, float %Z) { define float @test8(float %X, float %Y, float %Z) {
; CHECK-LABEL: @test8 ; CHECK-LABEL: @test8(
; CHECK-NEXT: fmul fast float %Y, %X ; CHECK-NEXT: [[A:%.*]] = fmul fast float %Y, %X
; CHECK-NEXT: fsub fast float %Z ; CHECK-NEXT: [[C:%.*]] = fsub fast float %Z, [[A]]
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[C]]
;
%A = fsub fast float 0.0, %X %A = fsub fast float 0.0, %X
%B = fmul fast float %A, %Y %B = fmul fast float %A, %Y
; (-X)*Y + Z -> Z-X*Y ; (-X)*Y + Z -> Z-X*Y
@ -133,30 +145,30 @@ define float @test8(float %X, float %Y, float %Z) {
} }
define float @test9(float %X) { define float @test9(float %X) {
; CHECK-LABEL: @test9 ; CHECK-LABEL: @test9(
; CHECK-NEXT: fmul fast float %X, 9.400000e+01 ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float %X, 9.400000e+01
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[FACTOR]]
;
%Y = fmul fast float %X, 4.700000e+01 %Y = fmul fast float %X, 4.700000e+01
%Z = fadd fast float %Y, %Y %Z = fadd fast float %Y, %Y
ret float %Z ret float %Z
} }
define float @test10(float %X) { define float @test10(float %X) {
; CHECK-LABEL: @test10 ; CHECK-LABEL: @test10(
; CHECK-NEXT: fmul fast float %X, 3.000000e+00 ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float %X, 3.000000e+00
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[FACTOR]]
;
%Y = fadd fast float %X ,%X %Y = fadd fast float %X ,%X
%Z = fadd fast float %Y, %X %Z = fadd fast float %Y, %X
ret float %Z ret float %Z
} }
define float @test11(float %W) { define float @test11(float %W) {
; CHECK-LABEL: test11 ; CHECK-LABEL: @test11(
; CHECK-NEXT: fmul fast float %W, 3.810000e+02 ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float %W, 3.810000e+02
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[FACTOR]]
;
%X = fmul fast float %W, 127.0 %X = fmul fast float %W, 127.0
%Y = fadd fast float %X ,%X %Y = fadd fast float %X ,%X
%Z = fadd fast float %Y, %X %Z = fadd fast float %Y, %X
@ -164,11 +176,11 @@ define float @test11(float %W) {
} }
define float @test12(float %X) { define float @test12(float %X) {
; CHECK-LABEL: @test12 ; CHECK-LABEL: @test12(
; CHECK-NEXT: fmul fast float %X, -3.000000e+00 ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float %X, -3.000000e+00
; CHECK-NEXT: fadd fast float %factor, 6.000000e+00 ; CHECK-NEXT: [[Z:%.*]] = fadd fast float [[FACTOR]], 6.000000e+00
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[Z]]
;
%A = fsub fast float 1.000000e+00, %X %A = fsub fast float 1.000000e+00, %X
%B = fsub fast float 2.000000e+00, %X %B = fsub fast float 2.000000e+00, %X
%C = fsub fast float 3.000000e+00, %X %C = fsub fast float 3.000000e+00, %X
@ -178,11 +190,11 @@ define float @test12(float %X) {
} }
define float @test13(float %X1, float %X2, float %X3) { define float @test13(float %X1, float %X2, float %X3) {
; CHECK-LABEL: @test13 ; CHECK-LABEL: @test13(
; CHECK-NEXT: fsub fast float %X3, %X2 ; CHECK-NEXT: [[REASS_ADD:%.*]] = fsub fast float %X3, %X2
; CHECK-NEXT: fmul fast float {{.*}}, %X1 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD]], %X1
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[REASS_MUL]]
;
%A = fsub fast float 0.000000e+00, %X1 %A = fsub fast float 0.000000e+00, %X1
%B = fmul fast float %A, %X2 ; -X1*X2 %B = fmul fast float %A, %X2 ; -X1*X2
%C = fmul fast float %X1, %X3 ; X1*X3 %C = fmul fast float %X1, %X3 ; X1*X3
@ -191,11 +203,11 @@ define float @test13(float %X1, float %X2, float %X3) {
} }
define float @test14(float %X1, float %X2) { define float @test14(float %X1, float %X2) {
; CHECK-LABEL: @test14 ; CHECK-LABEL: @test14(
; CHECK-NEXT: fsub fast float %X1, %X2 ; CHECK-NEXT: [[TMP1:%.*]] = fsub fast float %X1, %X2
; CHECK-NEXT: fmul fast float %1, 4.700000e+01 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[TMP1]], 4.700000e+01
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[TMP2]]
;
%B = fmul fast float %X1, 47. ; X1*47 %B = fmul fast float %X1, 47. ; X1*47
%C = fmul fast float %X2, -47. ; X2*-47 %C = fmul fast float %X2, -47. ; X2*-47
%D = fadd fast float %B, %C ; X1*47 + X2*-47 -> 47*(X1-X2) %D = fadd fast float %B, %C ; X1*47 + X2*-47 -> 47*(X1-X2)
@ -203,21 +215,21 @@ define float @test14(float %X1, float %X2) {
} }
define float @test15(float %arg) { define float @test15(float %arg) {
; CHECK-LABEL: test15 ; CHECK-LABEL: @test15(
; CHECK-NEXT: fmul fast float %arg, 1.440000e+02 ; CHECK-NEXT: [[T2:%.*]] = fmul fast float %arg, 1.440000e+02
; CHECK-NEXT: ret float %tmp2 ; CHECK-NEXT: ret float [[T2]]
;
%tmp1 = fmul fast float 1.200000e+01, %arg %t1 = fmul fast float 1.200000e+01, %arg
%tmp2 = fmul fast float %tmp1, 1.200000e+01 %t2 = fmul fast float %t1, 1.200000e+01
ret float %tmp2 ret float %t2
} }
; (b+(a+1234))+-a -> b+1234 ; (b+(a+1234))+-a -> b+1234
define float @test16(float %b, float %a) { define float @test16(float %b, float %a) {
; CHECK-LABEL: @test16 ; CHECK-LABEL: @test16(
; CHECK-NEXT: fadd fast float %b, 1.234000e+03 ; CHECK-NEXT: [[TMP1:%.*]] = fadd fast float %b, 1.234000e+03
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[TMP1]]
;
%1 = fadd fast float %a, 1234.0 %1 = fadd fast float %a, 1234.0
%2 = fadd fast float %b, %1 %2 = fadd fast float %b, %1
%3 = fsub fast float 0.0, %a %3 = fsub fast float 0.0, %a
@ -228,12 +240,12 @@ define float @test16(float %b, float %a) {
; Test that we can turn things like X*-(Y*Z) -> X*-1*Y*Z. ; Test that we can turn things like X*-(Y*Z) -> X*-1*Y*Z.
define float @test17(float %a, float %b, float %z) { define float @test17(float %a, float %b, float %z) {
; CHECK-LABEL: test17 ; CHECK-LABEL: @test17(
; CHECK-NEXT: fmul fast float %a, 1.234500e+04 ; CHECK-NEXT: [[E:%.*]] = fmul fast float %a, 1.234500e+04
; CHECK-NEXT: fmul fast float %e, %b ; CHECK-NEXT: [[F:%.*]] = fmul fast float [[E]], %b
; CHECK-NEXT: fmul fast float %f, %z ; CHECK-NEXT: [[G:%.*]] = fmul fast float [[F]], %z
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[G]]
;
%c = fsub fast float 0.000000e+00, %z %c = fsub fast float 0.000000e+00, %z
%d = fmul fast float %a, %b %d = fmul fast float %a, %b
%e = fmul fast float %c, %d %e = fmul fast float %c, %d
@ -243,11 +255,11 @@ define float @test17(float %a, float %b, float %z) {
} }
define float @test18(float %a, float %b, float %z) { define float @test18(float %a, float %b, float %z) {
; CHECK-LABEL: test18 ; CHECK-LABEL: @test18(
; CHECK-NEXT: fmul fast float %a, 4.000000e+01 ; CHECK-NEXT: [[E:%.*]] = fmul fast float %a, 4.000000e+01
; CHECK-NEXT: fmul fast float %e, %z ; CHECK-NEXT: [[F:%.*]] = fmul fast float [[E]], %z
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[F]]
;
%d = fmul fast float %z, 4.000000e+01 %d = fmul fast float %z, 4.000000e+01
%c = fsub fast float 0.000000e+00, %d %c = fsub fast float 0.000000e+00, %d
%e = fmul fast float %a, %c %e = fmul fast float %a, %c
@ -257,9 +269,10 @@ define float @test18(float %a, float %b, float %z) {
; With sub reassociation, constant folding can eliminate the 12 and -12 constants. ; With sub reassociation, constant folding can eliminate the 12 and -12 constants.
define float @test19(float %A, float %B) { define float @test19(float %A, float %B) {
; CHECK-LABEL: @test19 ; CHECK-LABEL: @test19(
; CHECK-NEXT: fsub fast float %A, %B ; CHECK-NEXT: [[Z:%.*]] = fsub fast float %A, %B
; CHECK-NEXT: ret float ; CHECK-NEXT: ret float [[Z]]
;
%X = fadd fast float -1.200000e+01, %A %X = fadd fast float -1.200000e+01, %A
%Y = fsub fast float %X, %B %Y = fsub fast float %X, %B
%Z = fadd fast float %Y, 1.200000e+01 %Z = fadd fast float %Y, 1.200000e+01
@ -268,18 +281,17 @@ define float @test19(float %A, float %B) {
; With sub reassociation, constant folding can eliminate the uses of %a. ; With sub reassociation, constant folding can eliminate the uses of %a.
define float @test20(float %a, float %b, float %c) nounwind { define float @test20(float %a, float %b, float %c) nounwind {
; CHECK-LABEL: @test20
; CHECK-NEXT: fsub fast float -0.000000e+00, %b
; CHECK-NEXT: fsub fast float %b.neg, %c
; CHECK-NEXT: ret float
; FIXME: Should be able to generate the below, which may expose more ; FIXME: Should be able to generate the below, which may expose more
; opportunites for FAdd reassociation. ; opportunites for FAdd reassociation.
; %sum = fadd fast float %c, %b ; %sum = fadd fast float %c, %b
; %tmp7 = fsub fast float 0, %sum ; %t7 = fsub fast float 0, %sum
; CHECK-LABEL: @test20(
%tmp3 = fsub fast float %a, %b ; CHECK-NEXT: [[B_NEG:%.*]] = fsub fast float -0.000000e+00, %b
%tmp5 = fsub fast float %tmp3, %c ; CHECK-NEXT: [[T7:%.*]] = fsub fast float [[B_NEG]], %c
%tmp7 = fsub fast float %tmp5, %a ; CHECK-NEXT: ret float [[T7]]
ret float %tmp7 ;
%t3 = fsub fast float %a, %b
%t5 = fsub fast float %t3, %c
%t7 = fsub fast float %t5, %a
ret float %t7
} }

View File

@ -3,13 +3,14 @@
declare void @use(float) declare void @use(float)
define void @test1(float %x, float %y) { define void @test1(float %x, float %y) {
; CHECK-LABEL: test1 ; CHECK-LABEL: @test1(
; CHECK: fmul fast float %y, %x ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float %y, %x
; CHECK: fmul fast float %y, %x ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float %y, %x
; CHECK: fsub fast float %1, %2 ; CHECK-NEXT: [[TMP3:%.*]] = fsub fast float [[TMP1]], [[TMP2]]
; CHECK: call void @use(float %{{.*}}) ; CHECK-NEXT: call void @use(float [[TMP1]])
; CHECK: call void @use(float %{{.*}}) ; CHECK-NEXT: call void @use(float [[TMP3]])
; CHECK-NEXT: ret void
;
%1 = fmul fast float %x, %y %1 = fmul fast float %x, %y
%2 = fmul fast float %y, %x %2 = fmul fast float %y, %x
%3 = fsub fast float %1, %2 %3 = fsub fast float %1, %2
@ -19,12 +20,12 @@ define void @test1(float %x, float %y) {
} }
define float @test2(float %x, float %y) { define float @test2(float %x, float %y) {
; CHECK-LABEL: test2 ; CHECK-LABEL: @test2(
; CHECK-NEXT: fmul fast float %y, %x ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float %y, %x
; CHECK-NEXT: fmul fast float %y, %x ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float %y, %x
; CHECK-NEXT: fsub fast float %1, %2 ; CHECK-NEXT: [[TMP3:%.*]] = fsub fast float [[TMP1]], [[TMP2]]
; CHECK-NEXT: ret float %3 ; CHECK-NEXT: ret float [[TMP3]]
;
%1 = fmul fast float %x, %y %1 = fmul fast float %x, %y
%2 = fmul fast float %y, %x %2 = fmul fast float %y, %x
%3 = fsub fast float %1, %2 %3 = fsub fast float %1, %2
@ -32,13 +33,14 @@ define float @test2(float %x, float %y) {
} }
define float @test3(float %x, float %y) { define float @test3(float %x, float %y) {
; CHECK-LABEL: test3 ; CHECK-LABEL: @test3(
; CHECK-NEXT: %factor = fmul fast float %x, 2.000000e+00 ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float %x, 2.000000e+00
; CHECK-NEXT: %tmp1 = fmul fast float %factor, %y ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[FACTOR]], %y
; CHECK-NEXT: ret float %tmp1 ; CHECK-NEXT: ret float [[REASS_MUL]]
;
%1 = fmul fast float %x, %y %1 = fmul fast float %x, %y
%2 = fmul fast float %y, %x %2 = fmul fast float %y, %x
%3 = fadd fast float %1, %2 %3 = fadd fast float %1, %2
ret float %3 ret float %3
} }

View File

@ -1,13 +1,14 @@
; RUN: opt < %s -reassociate -S | FileCheck %s ; RUN: opt < %s -reassociate -S | FileCheck %s
define float @fmultistep1(float %a, float %b, float %c) {
; Check that a*a*b+a*a*c is turned into a*(a*(b+c)). ; Check that a*a*b+a*a*c is turned into a*(a*(b+c)).
; CHECK-LABEL: @fmultistep1
; CHECK-NEXT: [[TMP1:%tmp.*]] = fadd fast float %c, %b
; CHECK-NEXT: [[TMP2:%tmp.*]] = fmul fast float %a, %a
; CHECK-NEXT: fmul fast float [[TMP2]], [[TMP1]]
; CHECK-NEXT: ret float
define float @fmultistep1(float %a, float %b, float %c) {
; CHECK-LABEL: @fmultistep1(
; CHECK-NEXT: [[REASS_ADD1:%.*]] = fadd fast float %c, %b
; CHECK-NEXT: [[REASS_MUL2:%.*]] = fmul fast float %a, %a
; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_MUL:%.*]]2, [[REASS_ADD1]]
; CHECK-NEXT: ret float [[REASS_MUL]]
;
%t0 = fmul fast float %a, %b %t0 = fmul fast float %a, %b
%t1 = fmul fast float %a, %t0 ; a*(a*b) %t1 = fmul fast float %a, %t0 ; a*(a*b)
%t2 = fmul fast float %a, %c %t2 = fmul fast float %a, %c
@ -16,17 +17,19 @@ define float @fmultistep1(float %a, float %b, float %c) {
ret float %t4 ret float %t4
} }
define float @fmultistep2(float %a, float %b, float %c, float %d) {
; Check that a*b+a*c+d is turned into a*(b+c)+d. ; Check that a*b+a*c+d is turned into a*(b+c)+d.
; CHECK-LABEL: @fmultistep2
; CHECK-NEXT: fadd fast float %c, %b
; CHECK-NEXT: fmul fast float %tmp, %a
; CHECK-NEXT: fadd fast float %tmp1, %d
; CHECK-NEXT: ret float
define float @fmultistep2(float %a, float %b, float %c, float %d) {
; CHECK-LABEL: @fmultistep2(
; CHECK-NEXT: [[REASS_ADD:%.*]] = fadd fast float %c, %b
; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD]], %a
; CHECK-NEXT: [[T3:%.*]] = fadd fast float [[REASS_MUL]], %d
; CHECK-NEXT: ret float [[T3]]
;
%t0 = fmul fast float %a, %b %t0 = fmul fast float %a, %b
%t1 = fmul fast float %a, %c %t1 = fmul fast float %a, %c
%t2 = fadd fast float %t1, %d ; a*c+d %t2 = fadd fast float %t1, %d ; a*c+d
%t3 = fadd fast float %t0, %t2 ; a*b+(a*c+d) %t3 = fadd fast float %t0, %t2 ; a*b+(a*c+d)
ret float %t3 ret float %t3
} }

View File

@ -1,12 +1,14 @@
; RUN: opt -reassociate %s -S | FileCheck %s ; RUN: opt -reassociate %s -S | FileCheck %s
define float @foo(float %a,float %b, float %c) { define float @foo(float %a,float %b, float %c) {
; CHECK: %mul3 = fmul float %a, %b ; CHECK-LABEL: @foo(
; CHECK-NEXT: fmul fast float %c, 2.000000e+00 ; CHECK-NEXT: [[MUL3:%.*]] = fmul float %a, %b
; CHECK-NEXT: fadd fast float %factor, %b ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float %c, 2.000000e+00
; CHECK-NEXT: fmul fast float %tmp1, %a ; CHECK-NEXT: [[REASS_ADD1:%.*]] = fadd fast float [[FACTOR]], %b
; CHECK-NEXT: fadd fast float %tmp2, %mul3 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD1]], %a
; CHECK-NEXT: ret float ; CHECK-NEXT: [[ADD3:%.*]] = fadd fast float [[REASS_MUL]], [[MUL3]]
; CHECK-NEXT: ret float [[ADD3]]
;
%mul1 = fmul fast float %a, %c %mul1 = fmul fast float %a, %c
%mul2 = fmul fast float %a, %b %mul2 = fmul fast float %a, %b
%mul3 = fmul float %a, %b %mul3 = fmul float %a, %b

View File

@ -2,46 +2,43 @@
define i32 @test1(i32 %a, i32 %b) { define i32 @test1(i32 %a, i32 %b) {
; CHECK-LABEL: @test1( ; CHECK-LABEL: @test1(
; CHECK: mul i32 %a, %a ; CHECK-NEXT: [[T2:%.*]] = mul i32 %a, %a
; CHECK-NEXT: mul i32 %a, 2 ; CHECK-NEXT: [[T6:%.*]] = mul i32 %a, 2
; CHECK-NEXT: add ; CHECK-NEXT: [[REASS_ADD:%.*]] = add i32 [[T6]], %b
; CHECK-NEXT: mul ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 [[REASS_ADD]], %b
; CHECK-NEXT: add ; CHECK-NEXT: [[T11:%.*]] = add i32 [[REASS_MUL]], [[T2]]
; CHECK-NEXT: ret ; CHECK-NEXT: ret i32 [[T11]]
;
entry: %t2 = mul i32 %a, %a
%tmp.2 = mul i32 %a, %a %t5 = shl i32 %a, 1
%tmp.5 = shl i32 %a, 1 %t6 = mul i32 %t5, %b
%tmp.6 = mul i32 %tmp.5, %b %t8 = mul i32 %b, %b
%tmp.10 = mul i32 %b, %b %t7 = add i32 %t6, %t2
%tmp.7 = add i32 %tmp.6, %tmp.2 %t11 = add i32 %t7, %t8
%tmp.11 = add i32 %tmp.7, %tmp.10 ret i32 %t11
ret i32 %tmp.11
} }
define i32 @test2(i32 %t) { define i32 @test2(i32 %t) {
; CHECK-LABEL: @test2( ; CHECK-LABEL: @test2(
; CHECK: mul ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 %t, 42
; CHECK-NEXT: add ; CHECK-NEXT: [[D:%.*]] = add i32 [[REASS_MUL]], 15
; CHECK-NEXT: ret ; CHECK-NEXT: ret i32 [[D]]
;
entry: %a = mul i32 %t, 6
%a = mul i32 %t, 6 %b = mul i32 %t, 36
%b = mul i32 %t, 36 %c = add i32 %b, 15
%c = add i32 %b, 15 %d = add i32 %c, %a
%d = add i32 %c, %a ret i32 %d
ret i32 %d
} }
define i32 @test3(i32 %x) {
; (x^8) ; (x^8)
define i32 @test3(i32 %x) {
; CHECK-LABEL: @test3( ; CHECK-LABEL: @test3(
; CHECK: mul ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP2]]
; CHECK-NEXT: ret ; CHECK-NEXT: ret i32 [[TMP3]]
;
entry:
%a = mul i32 %x, %x %a = mul i32 %x, %x
%b = mul i32 %a, %x %b = mul i32 %a, %x
%c = mul i32 %b, %x %c = mul i32 %b, %x
@ -52,16 +49,15 @@ entry:
ret i32 %g ret i32 %g
} }
define i32 @test4(i32 %x) {
; (x^7) ; (x^7)
define i32 @test4(i32 %x) {
; CHECK-LABEL: @test4( ; CHECK-LABEL: @test4(
; CHECK: mul ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %x
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], %x
; CHECK-NEXT: mul ; CHECK-NEXT: [[F:%.*]] = mul i32 [[TMP3]], [[TMP2]]
; CHECK-NEXT: ret ; CHECK-NEXT: ret i32 [[F]]
;
entry:
%a = mul i32 %x, %x %a = mul i32 %x, %x
%b = mul i32 %a, %x %b = mul i32 %a, %x
%c = mul i32 %b, %x %c = mul i32 %b, %x
@ -71,15 +67,14 @@ entry:
ret i32 %f ret i32 %f
} }
define i32 @test5(i32 %x, i32 %y) {
; (x^4) * (y^2) ; (x^4) * (y^2)
define i32 @test5(i32 %x, i32 %y) {
; CHECK-LABEL: @test5( ; CHECK-LABEL: @test5(
; CHECK: mul ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %y
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP2]]
; CHECK-NEXT: ret ; CHECK-NEXT: ret i32 [[TMP3]]
;
entry:
%a = mul i32 %x, %y %a = mul i32 %x, %y
%b = mul i32 %a, %y %b = mul i32 %a, %y
%c = mul i32 %b, %x %c = mul i32 %b, %x
@ -88,18 +83,17 @@ entry:
ret i32 %e ret i32 %e
} }
define i32 @test6(i32 %x, i32 %y, i32 %z) {
; (x^5) * (y^3) * z ; (x^5) * (y^3) * z
define i32 @test6(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @test6( ; CHECK-LABEL: @test6(
; CHECK: mul ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %y
; CHECK-NEXT: mul ; CHECK-NEXT: [[F:%.*]] = mul i32 %y, %x
; CHECK-NEXT: mul ; CHECK-NEXT: [[G:%.*]] = mul i32 [[F]], [[TMP2]]
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[G]], [[TMP2]]
; CHECK-NEXT: mul ; CHECK-NEXT: [[H:%.*]] = mul i32 [[TMP3]], %z
; CHECK-NEXT: ret ; CHECK-NEXT: ret i32 [[H]]
;
entry:
%a = mul i32 %x, %y %a = mul i32 %x, %y
%b = mul i32 %a, %x %b = mul i32 %a, %x
%c = mul i32 %b, %y %c = mul i32 %b, %y
@ -111,17 +105,16 @@ entry:
ret i32 %h ret i32 %h
} }
define i32 @test7(i32 %x, i32 %y, i32 %z) {
; (x^4) * (y^3) * (z^2) ; (x^4) * (y^3) * (z^2)
define i32 @test7(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @test7( ; CHECK-LABEL: @test7(
; CHECK: mul ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %y
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], %z
; CHECK-NEXT: mul ; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP3]], %y
; CHECK-NEXT: mul ; CHECK-NEXT: [[H:%.*]] = mul i32 [[TMP4]], [[TMP3]]
; CHECK-NEXT: ret ; CHECK-NEXT: ret i32 [[H]]
;
entry:
%a = mul i32 %y, %x %a = mul i32 %y, %x
%b = mul i32 %a, %z %b = mul i32 %a, %z
%c = mul i32 %b, %z %c = mul i32 %b, %z
@ -132,3 +125,4 @@ entry:
%h = mul i32 %g, %x %h = mul i32 %g, %x
ret i32 %h ret i32 %h
} }

View File

@ -1,30 +1,35 @@
; RUN: opt < %s -reassociate -S | FileCheck %s ; RUN: opt < %s -reassociate -S | FileCheck %s
define i64 @multistep1(i64 %a, i64 %b, i64 %c) {
; Check that a*a*b+a*a*c is turned into a*(a*(b+c)). ; Check that a*a*b+a*a*c is turned into a*(a*(b+c)).
define i64 @multistep1(i64 %a, i64 %b, i64 %c) {
; CHECK-LABEL: @multistep1( ; CHECK-LABEL: @multistep1(
; CHECK-NEXT: [[REASS_ADD1:%.*]] = add i64 %c, %b
; CHECK-NEXT: [[REASS_MUL2:%.*]] = mul i64 %a, %a
; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i64 [[REASS_MUL:%.*]]2, [[REASS_ADD1]]
; CHECK-NEXT: ret i64 [[REASS_MUL]]
;
%t0 = mul i64 %a, %b %t0 = mul i64 %a, %b
%t1 = mul i64 %a, %t0 ; a*(a*b) %t1 = mul i64 %a, %t0 ; a*(a*b)
%t2 = mul i64 %a, %c %t2 = mul i64 %a, %c
%t3 = mul i64 %a, %t2 ; a*(a*c) %t3 = mul i64 %a, %t2 ; a*(a*c)
%t4 = add i64 %t1, %t3 %t4 = add i64 %t1, %t3
; CHECK-NEXT: [[TMP1:%tmp.*]] = add i64 %c, %b
; CHECK-NEXT: [[TMP2:%tmp.*]] = mul i64 %a, %a
; CHECK-NEXT: mul i64 [[TMP2]], [[TMP1]]
; CHECK-NEXT: ret
ret i64 %t4 ret i64 %t4
} }
define i64 @multistep2(i64 %a, i64 %b, i64 %c, i64 %d) {
; Check that a*b+a*c+d is turned into a*(b+c)+d. ; Check that a*b+a*c+d is turned into a*(b+c)+d.
define i64 @multistep2(i64 %a, i64 %b, i64 %c, i64 %d) {
; CHECK-LABEL: @multistep2( ; CHECK-LABEL: @multistep2(
; CHECK-NEXT: [[REASS_ADD:%.*]] = add i64 %c, %b
; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i64 [[REASS_ADD]], %a
; CHECK-NEXT: [[T3:%.*]] = add i64 [[REASS_MUL]], %d
; CHECK-NEXT: ret i64 [[T3]]
;
%t0 = mul i64 %a, %b %t0 = mul i64 %a, %b
%t1 = mul i64 %a, %c %t1 = mul i64 %a, %c
%t2 = add i64 %t1, %d ; a*c+d %t2 = add i64 %t1, %d ; a*c+d
%t3 = add i64 %t0, %t2 ; a*b+(a*c+d) %t3 = add i64 %t0, %t2 ; a*b+(a*c+d)
; CHECK-NEXT: add i64 %c, %b
; CHECK-NEXT: mul i64 %tmp{{.*}}, %a
; CHECK-NEXT: add i64 %tmp{{.*}}, %d
; CHECK-NEXT: ret
ret i64 %t3 ret i64 %t3
} }

View File

@ -1,31 +1,37 @@
; RUN: opt < %s -reassociate -S | FileCheck %s ; RUN: opt < %s -reassociate -S | FileCheck %s
; CHECK-LABEL: faddsubAssoc1
; CHECK: [[TMP1:%tmp.*]] = fmul fast half %a, 0xH4500
; CHECK: [[TMP2:%tmp.*]] = fmul fast half %b, 0xH4500
; CHECK: fsub fast half [[TMP2]], [[TMP1]]
; CHECK: ret
; Input is A op (B op C) ; Input is A op (B op C)
define half @faddsubAssoc1(half %a, half %b) { define half @faddsubAssoc1(half %a, half %b) {
%tmp1 = fmul fast half %b, 0xH4200 ; 3*b ; CHECK-LABEL: @faddsubAssoc1(
%tmp2 = fmul fast half %a, 0xH4500 ; 5*a ; CHECK-NEXT: [[T2_NEG:%.*]] = fmul fast half %a, 0xH4500
%tmp3 = fmul fast half %b, 0xH4000 ; 2*b ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast half %b, 0xH4500
%tmp4 = fsub fast half %tmp2, %tmp1 ; 5 * a - 3 * b ; CHECK-NEXT: [[T51:%.*]] = fsub fast half [[REASS_MUL]], [[T2_NEG]]
%tmp5 = fsub fast half %tmp3, %tmp4 ; 2 * b - ( 5 * a - 3 * b) ; CHECK-NEXT: [[T5:%.*]] = fadd fast half [[REASS_MUL]], [[T2_NEG]]
ret half %tmp5 ; = 5 * (b - a) ; CHECK-NEXT: ret half [[T51]]
;
%t1 = fmul fast half %b, 0xH4200 ; 3*b
%t2 = fmul fast half %a, 0xH4500 ; 5*a
%t3 = fmul fast half %b, 0xH4000 ; 2*b
%t4 = fsub fast half %t2, %t1 ; 5 * a - 3 * b
%t5 = fsub fast half %t3, %t4 ; 2 * b - ( 5 * a - 3 * b)
ret half %t5 ; = 5 * (b - a)
} }
; CHECK-LABEL: faddsubAssoc2
; CHECK: [[TMP1:%tmp.*]] = fmul fast half %a, 0xH4500
; CHECK: [[TMP2:%tmp.*]] = fmul fast half %b, 0xH3C00
; CHECK: fadd fast half [[TMP2]], [[TMP1]]
; CHECK: ret
; Input is (A op B) op C ; Input is (A op B) op C
define half @faddsubAssoc2(half %a, half %b) { define half @faddsubAssoc2(half %a, half %b) {
%tmp1 = fmul fast half %b, 0xH4200 ; 3*b ; CHECK-LABEL: @faddsubAssoc2(
%tmp2 = fmul fast half %a, 0xH4500 ; 5*a ; CHECK-NEXT: [[T2:%.*]] = fmul fast half %a, 0xH4500
%tmp3 = fmul fast half %b, 0xH4000 ; 2*b ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast half %b, 0xH3C00
%tmp4 = fadd fast half %tmp2, %tmp1 ; 5 * a + 3 * b ; CHECK-NEXT: [[T5:%.*]] = fadd fast half [[REASS_MUL]], [[T2]]
%tmp5 = fsub fast half %tmp4, %tmp3 ; (5 * a + 3 * b) - (2 * b) ; CHECK-NEXT: ret half [[T5]]
ret half %tmp5 ; = 5 * a + b ;
%t1 = fmul fast half %b, 0xH4200 ; 3*b
%t2 = fmul fast half %a, 0xH4500 ; 5*a
%t3 = fmul fast half %b, 0xH4000 ; 2*b
%t4 = fadd fast half %t2, %t1 ; 5 * a + 3 * b
%t5 = fsub fast half %t4, %t3 ; (5 * a + 3 * b) - (2 * b)
ret half %t5 ; = 5 * a + b
} }

View File

@ -1,14 +1,16 @@
; There should be exactly one shift and one add left.
; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s ; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s
define i32 @test1(i32 %X, i32 %Y) { ; There should be exactly one shift and one add left.
; CHECK-LABEL: test1
; CHECK-NEXT: %tmp = add i32 %Y, %X
; CHECK-NEXT: %tmp1 = shl i32 %tmp, 1
; CHECK-NEXT: ret i32 %tmp1
%tmp.2 = shl i32 %X, 1 define i32 @test1(i32 %X, i32 %Y) {
%tmp.6 = shl i32 %Y, 1 ; CHECK-LABEL: @test1(
%tmp.4 = add i32 %tmp.6, %tmp.2 ; CHECK-NEXT: [[REASS_ADD:%.*]] = add i32 %Y, %X
ret i32 %tmp.4 ; CHECK-NEXT: [[REASS_MUL:%.*]] = shl i32 [[REASS_ADD]], 1
; CHECK-NEXT: ret i32 [[REASS_MUL]]
;
%t2 = shl i32 %X, 1
%t6 = shl i32 %Y, 1
%t4 = add i32 %t6, %t2
ret i32 %t4
} }