[Reassociate] As the expression tree is rewritten make sure the operands are
emitted in canonical form.
llvm-svn: 222142
diff --git a/llvm/test/Transforms/Reassociate/2002-05-15-MissedTree.ll b/llvm/test/Transforms/Reassociate/2002-05-15-MissedTree.ll
index 5f3c9209..e7e1ce8 100644
--- a/llvm/test/Transforms/Reassociate/2002-05-15-MissedTree.ll
+++ b/llvm/test/Transforms/Reassociate/2002-05-15-MissedTree.ll
@@ -2,7 +2,7 @@
define i32 @test1(i32 %A, i32 %B) {
; CHECK-LABEL: test1
-; CHECK: %Z = add i32 %B, %A
+; CHECK: %Z = add i32 %A, %B
; CHECK: ret i32 %Z
%W = add i32 %B, -5
%Y = add i32 %A, 5
diff --git a/llvm/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll b/llvm/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll
index 29c178f..1473c72 100644
--- a/llvm/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll
+++ b/llvm/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll
@@ -16,7 +16,7 @@
; With sub reassociation, constant folding can eliminate the two 12 constants.
define i32 @test2(i32 %A, i32 %B, i32 %C, i32 %D) {
; CHECK-LABEL: test2
-; CHECK-NEXT: %sum = add i32 %B, %A
+; CHECK-NEXT: %sum = add i32 %A, %B
; CHECK-NEXT: %sum1 = add i32 %sum, %C
; CHECK-NEXT: %Q = sub i32 %D, %sum1
; CHECK-NEXT: ret i32 %Q
diff --git a/llvm/test/Transforms/Reassociate/basictest.ll b/llvm/test/Transforms/Reassociate/basictest.ll
index 0194ce2..ed09ffd 100644
--- a/llvm/test/Transforms/Reassociate/basictest.ll
+++ b/llvm/test/Transforms/Reassociate/basictest.ll
@@ -17,7 +17,7 @@
ret i32 %reg117
; CHECK-LABEL: @test2
-; CHECK-NEXT: %reg117 = add i32 %reg1111, %reg109
+; CHECK-NEXT: %reg117 = add i32 %reg109, %reg1111
; CHECK-NEXT: ret i32 %reg117
}
@@ -121,7 +121,7 @@
ret i32 %r
; CHECK-LABEL: @test7
-; CHECK-NEXT: add i32 %C, %B
+; CHECK-NEXT: add i32 %B, %C
; CHECK-NEXT: mul i32
; CHECK-NEXT: mul i32
; CHECK-NEXT: ret i32
@@ -135,7 +135,7 @@
ret i32 %C
; CHECK-LABEL: @test8
-; CHECK-NEXT: %A = mul i32 %Y, %X
+; CHECK-NEXT: %A = mul i32 %X, %Y
; CHECK-NEXT: %C = sub i32 %Z, %A
; CHECK-NEXT: ret i32 %C
}
diff --git a/llvm/test/Transforms/Reassociate/canonicalize-neg-const.ll b/llvm/test/Transforms/Reassociate/canonicalize-neg-const.ll
index e85a963..1c86312 100644
--- a/llvm/test/Transforms/Reassociate/canonicalize-neg-const.ll
+++ b/llvm/test/Transforms/Reassociate/canonicalize-neg-const.ll
@@ -53,7 +53,7 @@
define i64 @test4(i64 %x, i64 %y) {
; CHECK-LABEL: @test4
; CHECK-NEXT: mul i64 %y, 1234
-; CHECK-NEXT: add i64 %mul, %x
+; CHECK-NEXT: add i64 %x, %mul
; CHECK-NEXT: ret i64 %sub
%mul = mul i64 %y, -1234
diff --git a/llvm/test/Transforms/Reassociate/commute.ll b/llvm/test/Transforms/Reassociate/commute.ll
index 760e51b..1c80248 100644
--- a/llvm/test/Transforms/Reassociate/commute.ll
+++ b/llvm/test/Transforms/Reassociate/commute.ll
@@ -4,8 +4,8 @@
define void @test1(i32 %x, i32 %y) {
; CHECK-LABEL: test1
-; CHECK: mul i32 %y, %x
-; CHECK: mul i32 %y, %x
+; CHECK: mul i32 %x, %y
+; CHECK: mul i32 %x, %y
; CHECK: sub i32 %1, %2
; CHECK: call void @use(i32 %{{.*}})
; CHECK: call void @use(i32 %{{.*}})
diff --git a/llvm/test/Transforms/Reassociate/fast-SubReassociate.ll b/llvm/test/Transforms/Reassociate/fast-SubReassociate.ll
index db4191a..4afd646 100644
--- a/llvm/test/Transforms/Reassociate/fast-SubReassociate.ll
+++ b/llvm/test/Transforms/Reassociate/fast-SubReassociate.ll
@@ -49,8 +49,8 @@
; With sub reassociation, constant folding can eliminate the two 12 constants.
define float @test4(float %A, float %B, float %C, float %D) {
; CHECK-LABEL: test4
-; CHECK-NEXT: %B.neg = fsub fast float -0.000000e+00, %B
-; CHECK-NEXT: %O.neg = fsub fast float %B.neg, %A
+; CHECK-NEXT: %A.neg = fsub fast float -0.000000e+00, %A
+; CHECK-NEXT: %O.neg = fsub fast float %A.neg, %B
; CHECK-NEXT: %P = fsub fast float %O.neg, %C
; CHECK-NEXT: %Q = fadd fast float %P, %D
; CHECK-NEXT: ret float %Q
diff --git a/llvm/test/Transforms/Reassociate/fast-basictest.ll b/llvm/test/Transforms/Reassociate/fast-basictest.ll
index 67b07f4..4d287fb 100644
--- a/llvm/test/Transforms/Reassociate/fast-basictest.ll
+++ b/llvm/test/Transforms/Reassociate/fast-basictest.ll
@@ -26,7 +26,7 @@
define float @test3(float %reg109, float %reg1111) {
; CHECK-LABEL: @test3
-; CHECK-NEXT: %reg117 = fadd fast float %reg109, %reg1111
+; CHECK-NEXT: %reg117 = fadd fast float %reg1111, %reg109
; CHECK-NEXT: ret float %reg117
%reg115 = fadd fast float %reg109, -3.000000e+01
@@ -106,7 +106,7 @@
define float @test7(float %A, float %B, float %C) {
; CHECK-LABEL: @test7
-; CHECK-NEXT: fadd fast float %C, %B
+; CHECK-NEXT: fadd fast float %B, %C
; CHECK-NEXT: fmul fast float %A, %A
; CHECK-NEXT: fmul fast float %1, %tmp2
; CHECK-NEXT: ret float
@@ -121,7 +121,7 @@
define float @test8(float %X, float %Y, float %Z) {
; CHECK-LABEL: @test8
-; CHECK-NEXT: fmul fast float %Y, %X
+; CHECK-NEXT: fmul fast float %X, %Y
; CHECK-NEXT: fsub fast float %Z
; CHECK-NEXT: ret float
@@ -269,8 +269,8 @@
; With sub reassociation, constant folding can eliminate the uses of %a.
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: fsub fast float -0.000000e+00, %c
+; CHECK-NEXT: fsub fast float %c.neg, %b
; CHECK-NEXT: ret float
; FIXME: Should be able to generate the below, which may expose more
diff --git a/llvm/test/Transforms/Reassociate/fast-fp-commute.ll b/llvm/test/Transforms/Reassociate/fast-fp-commute.ll
index ad89607..d3e0d9f 100644
--- a/llvm/test/Transforms/Reassociate/fast-fp-commute.ll
+++ b/llvm/test/Transforms/Reassociate/fast-fp-commute.ll
@@ -4,8 +4,8 @@
define void @test1(float %x, float %y) {
; CHECK-LABEL: test1
-; CHECK: fmul fast float %y, %x
-; CHECK: fmul fast float %y, %x
+; CHECK: fmul fast float %x, %y
+; CHECK: fmul fast float %x, %y
; CHECK: fsub fast float %1, %2
; CHECK: call void @use(float %{{.*}})
; CHECK: call void @use(float %{{.*}})
@@ -20,8 +20,8 @@
define float @test2(float %x, float %y) {
; CHECK-LABEL: test2
-; CHECK-NEXT: fmul fast float %y, %x
-; CHECK-NEXT: fmul fast float %y, %x
+; CHECK-NEXT: fmul fast float %x, %y
+; CHECK-NEXT: fmul fast float %x, %y
; CHECK-NEXT: fsub fast float %1, %2
; CHECK-NEXT: ret float %3
@@ -33,8 +33,8 @@
define float @test3(float %x, float %y) {
; CHECK-LABEL: test3
-; CHECK-NEXT: %factor = fmul fast float %y, 2.000000e+00
-; CHECK-NEXT: %tmp1 = fmul fast float %factor, %x
+; CHECK-NEXT: %factor = fmul fast float %x, 2.000000e+00
+; CHECK-NEXT: %tmp1 = fmul fast float %factor, %y
; CHECK-NEXT: ret float %tmp1
%1 = fmul fast float %x, %y
diff --git a/llvm/test/Transforms/Reassociate/fast-multistep.ll b/llvm/test/Transforms/Reassociate/fast-multistep.ll
index 45e15c7..5671b0f 100644
--- a/llvm/test/Transforms/Reassociate/fast-multistep.ll
+++ b/llvm/test/Transforms/Reassociate/fast-multistep.ll
@@ -3,9 +3,9 @@
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-LABEL: @fmultistep1
-; CHECK-NEXT: fadd fast float %c, %b
+; CHECK-NEXT: fadd fast float %b, %c
; CHECK-NEXT: fmul fast float %a, %tmp2
-; CHECK-NEXT: fmul fast float %tmp3, %a
+; CHECK-NEXT: fmul fast float %a, %tmp3
; CHECK-NEXT: ret float
%t0 = fmul fast float %a, %b
@@ -19,9 +19,9 @@
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-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: fadd fast float %b, %c
+; CHECK-NEXT: fmul fast float %a, %tmp
+; CHECK-NEXT: fadd fast float %d, %tmp1
; CHECK-NEXT: ret float
%t0 = fmul fast float %a, %b
diff --git a/llvm/test/Transforms/Reassociate/mixed-fast-nonfast-fp.ll b/llvm/test/Transforms/Reassociate/mixed-fast-nonfast-fp.ll
index f51c0c1..8ca0ff6 100644
--- a/llvm/test/Transforms/Reassociate/mixed-fast-nonfast-fp.ll
+++ b/llvm/test/Transforms/Reassociate/mixed-fast-nonfast-fp.ll
@@ -3,9 +3,9 @@
define float @foo(float %a,float %b, float %c) {
; CHECK: %mul3 = fmul float %a, %b
; CHECK-NEXT: fmul fast float %c, 2.000000e+00
-; CHECK-NEXT: fadd fast float %factor, %b
-; CHECK-NEXT: fmul fast float %tmp1, %a
-; CHECK-NEXT: fadd fast float %tmp2, %mul3
+; CHECK-NEXT: fadd fast float %b, %factor
+; CHECK-NEXT: fmul fast float %a, %tmp1
+; CHECK-NEXT: fadd fast float %mul3, %tmp2
; CHECK-NEXT: ret float
%mul1 = fmul fast float %a, %c
%mul2 = fmul fast float %a, %b
diff --git a/llvm/test/Transforms/Reassociate/multistep.ll b/llvm/test/Transforms/Reassociate/multistep.ll
index c499646..03ed183 100644
--- a/llvm/test/Transforms/Reassociate/multistep.ll
+++ b/llvm/test/Transforms/Reassociate/multistep.ll
@@ -8,9 +8,9 @@
%t2 = mul i64 %a, %c
%t3 = mul i64 %a, %t2 ; a*(a*c)
%t4 = add i64 %t1, %t3
-; CHECK-NEXT: add i64 %c, %b
+; CHECK-NEXT: add i64 %b, %c
; CHECK-NEXT: mul i64 %a, %tmp{{.*}}
-; CHECK-NEXT: mul i64 %tmp{{.*}}, %a
+; CHECK-NEXT: mul i64 %a, %tmp{{.*}}
; CHECK-NEXT: ret
ret i64 %t4
}
@@ -22,9 +22,9 @@
%t1 = mul i64 %a, %c
%t2 = add i64 %t1, %d ; 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: add i64 %b, %c
+; CHECK-NEXT: mul i64 %a, %tmp{{.*}}
+; CHECK-NEXT: add i64 %d, %tmp{{.*}}
; CHECK-NEXT: ret
ret i64 %t3
}
diff --git a/llvm/test/Transforms/Reassociate/no-op.ll b/llvm/test/Transforms/Reassociate/no-op.ll
index 7b02df9..fe8d783 100644
--- a/llvm/test/Transforms/Reassociate/no-op.ll
+++ b/llvm/test/Transforms/Reassociate/no-op.ll
@@ -27,11 +27,11 @@
; The initial add doesn't change so should not lose the nsw flag.
; CHECK-LABEL: @test2(
%a0 = add nsw i32 %b, %a
-; CHECK-NEXT: %a0 = add nsw i32 %b, %a
+; CHECK-NEXT: %a0 = add nsw i32 %a, %b
%a1 = add nsw i32 %a0, %d
; CHECK-NEXT: %a1 = add i32 %a0, %c
%a2 = add nsw i32 %a1, %c
-; CHECK-NEXT: %a2 = add i32 %a1, %d
+; CHECK-NEXT: %a2 = add i32 %d, %a1
call void @use(i32 %a2)
; CHECK-NEXT: call void @use
ret void
diff --git a/llvm/test/Transforms/Reassociate/optional-flags.ll b/llvm/test/Transforms/Reassociate/optional-flags.ll
index bf599be..b8cd03e 100644
--- a/llvm/test/Transforms/Reassociate/optional-flags.ll
+++ b/llvm/test/Transforms/Reassociate/optional-flags.ll
@@ -4,8 +4,8 @@
; Reassociate should clear optional flags like nsw when reassociating.
; CHECK-LABEL: @test0(
-; CHECK: %y = add i64 %b, %a
-; CHECK: %z = add i64 %y, %c
+; CHECK: %y = add i64 %a, %b
+; CHECK: %z = add i64 %c, %y
define i64 @test0(i64 %a, i64 %b, i64 %c) {
%y = add nsw i64 %c, %b
%z = add i64 %y, %a
@@ -13,8 +13,8 @@
}
; CHECK-LABEL: @test1(
-; CHECK: %y = add i64 %b, %a
-; CHECK: %z = add i64 %y, %c
+; CHECK: %y = add i64 %a, %b
+; CHECK: %z = add i64 %c, %y
define i64 @test1(i64 %a, i64 %b, i64 %c) {
%y = add i64 %c, %b
%z = add nsw i64 %y, %a
@@ -22,7 +22,7 @@
}
; PR9215
-; CHECK: %s = add nsw i32 %y, %x
+; CHECK: %s = add nsw i32 %x, %y
define i32 @test2(i32 %x, i32 %y) {
%s = add nsw i32 %x, %y
ret i32 %s
diff --git a/llvm/test/Transforms/Reassociate/shift-factor.ll b/llvm/test/Transforms/Reassociate/shift-factor.ll
index 8fbf1b9..f63ed59 100644
--- a/llvm/test/Transforms/Reassociate/shift-factor.ll
+++ b/llvm/test/Transforms/Reassociate/shift-factor.ll
@@ -3,7 +3,7 @@
define i32 @test1(i32 %X, i32 %Y) {
; CHECK-LABEL: test1
-; CHECK-NEXT: %tmp = add i32 %Y, %X
+; CHECK-NEXT: %tmp = add i32 %X, %Y
; CHECK-NEXT: %tmp1 = shl i32 %tmp, 1
; CHECK-NEXT: ret i32 %tmp1
diff --git a/llvm/test/Transforms/Reassociate/subtest.ll b/llvm/test/Transforms/Reassociate/subtest.ll
index e6263d8..e0406a6 100644
--- a/llvm/test/Transforms/Reassociate/subtest.ll
+++ b/llvm/test/Transforms/Reassociate/subtest.ll
@@ -15,7 +15,7 @@
; With sub reassociation, constant folding can eliminate the uses of %a.
define i32 @test2(i32 %a, i32 %b, i32 %c) nounwind {
; CHECK-LABEL: @test2
-; CHECK-NEXT: %sum = add i32 %c, %b
+; CHECK-NEXT: %sum = add i32 %b, %c
; CHECK-NEXT: %tmp7 = sub i32 0, %sum
; CHECK-NEXT: ret i32 %tmp7
diff --git a/llvm/test/Transforms/Reassociate/xor_reassoc.ll b/llvm/test/Transforms/Reassociate/xor_reassoc.ll
index a226898..7af4f15 100644
--- a/llvm/test/Transforms/Reassociate/xor_reassoc.ll
+++ b/llvm/test/Transforms/Reassociate/xor_reassoc.ll
@@ -45,7 +45,7 @@
;CHECK-LABEL: @xor3(
;CHECK: %and.ra = and i32 %x, -436
;CHECK: %xor = xor i32 %y, 123
-;CHECK: %xor1 = xor i32 %xor, %and.ra
+;CHECK: %xor1 = xor i32 %and.ra, %xor
}
; Test rule: (x | c1) ^ c2 = (x & ~c1) ^ (c1 ^ c2)
@@ -57,7 +57,7 @@
; CHECK-LABEL: @xor4(
; CHECK: %and = and i32 %x, -124
; CHECK: %xor = xor i32 %y, 435
-; CHECK: %xor1 = xor i32 %xor, %and
+; CHECK: %xor1 = xor i32 %and, %xor
}
; ==========================================================================
@@ -89,7 +89,7 @@
ret i32 %xor1
; CHECK-LABEL: @xor_special2(
; CHECK: %xor = xor i32 %y, 123
-; CHECK: %xor1 = xor i32 %xor, %x
+; CHECK: %xor1 = xor i32 %x, %xor
; CHECK: ret i32 %xor1
}