mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-01 00:33:09 +00:00
Revert "[Reassociate] As the expression tree is rewritten make sure the operands are"
This reverts commit r222142. This is causing/exposing an execution-time regression in spec2006/gcc and coremark on AArch64/A57/Ofast. Conflicts: test/Transforms/Reassociate/optional-flags.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222398 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fb1c650fd0
commit
503ec9826c
@ -791,11 +791,14 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
|
||||
Value *OldLHS = Op->getOperand(0);
|
||||
Value *OldRHS = Op->getOperand(1);
|
||||
|
||||
// The new operation differs trivially from the original.
|
||||
if ((NewLHS == OldLHS && NewRHS == OldRHS) ||
|
||||
(NewLHS == OldRHS && NewRHS == OldLHS)) {
|
||||
if (NewLHS == OldLHS && NewRHS == OldRHS)
|
||||
// Nothing changed, leave it alone.
|
||||
break;
|
||||
|
||||
if (NewLHS == OldRHS && NewRHS == OldLHS) {
|
||||
// The order of the operands was reversed. Swap them.
|
||||
DEBUG(dbgs() << "RA: " << *Op << '\n');
|
||||
canonicalizeOperands(Op);
|
||||
Op->swapOperands();
|
||||
DEBUG(dbgs() << "TO: " << *Op << '\n');
|
||||
MadeChange = true;
|
||||
++NumChanged;
|
||||
@ -817,8 +820,6 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
|
||||
NodesToRewrite.push_back(BO);
|
||||
Op->setOperand(1, NewRHS);
|
||||
}
|
||||
// Put the operands in canonical form.
|
||||
canonicalizeOperands(Op);
|
||||
DEBUG(dbgs() << "TO: " << *Op << '\n');
|
||||
|
||||
ExpressionChanged = Op;
|
||||
@ -855,7 +856,6 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
|
||||
// into it.
|
||||
BinaryOperator *BO = isReassociableOp(Op->getOperand(0), Opcode);
|
||||
if (BO && !NotRewritable.count(BO)) {
|
||||
canonicalizeOperands(Op);
|
||||
Op = BO;
|
||||
continue;
|
||||
}
|
||||
@ -880,7 +880,6 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
|
||||
|
||||
DEBUG(dbgs() << "RA: " << *Op << '\n');
|
||||
Op->setOperand(0, NewOp);
|
||||
canonicalizeOperands(Op);
|
||||
DEBUG(dbgs() << "TO: " << *Op << '\n');
|
||||
ExpressionChanged = Op;
|
||||
MadeChange = true;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
define i32 @test1(i32 %A, i32 %B) {
|
||||
; CHECK-LABEL: test1
|
||||
; CHECK: %Z = add i32 %A, %B
|
||||
; CHECK: %Z = add i32 %B, %A
|
||||
; CHECK: ret i32 %Z
|
||||
%W = add i32 %B, -5
|
||||
%Y = add i32 %A, 5
|
||||
|
@ -16,7 +16,7 @@ define i32 @test1(i32 %A, i32 %B) {
|
||||
; 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 %A, %B
|
||||
; CHECK-NEXT: %sum = add i32 %B, %A
|
||||
; CHECK-NEXT: %sum1 = add i32 %sum, %C
|
||||
; CHECK-NEXT: %Q = sub i32 %D, %sum1
|
||||
; CHECK-NEXT: ret i32 %Q
|
||||
|
@ -17,7 +17,7 @@ define i32 @test2(i32 %reg109, i32 %reg1111) {
|
||||
ret i32 %reg117
|
||||
|
||||
; CHECK-LABEL: @test2
|
||||
; CHECK-NEXT: %reg117 = add i32 %reg109, %reg1111
|
||||
; CHECK-NEXT: %reg117 = add i32 %reg1111, %reg109
|
||||
; CHECK-NEXT: ret i32 %reg117
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ define i32 @test7(i32 %A, i32 %B, i32 %C) {
|
||||
ret i32 %r
|
||||
|
||||
; CHECK-LABEL: @test7
|
||||
; CHECK-NEXT: add i32 %B, %C
|
||||
; CHECK-NEXT: add i32 %C, %B
|
||||
; CHECK-NEXT: mul i32
|
||||
; CHECK-NEXT: mul i32
|
||||
; CHECK-NEXT: ret i32
|
||||
@ -135,7 +135,7 @@ define i32 @test8(i32 %X, i32 %Y, i32 %Z) {
|
||||
ret i32 %C
|
||||
|
||||
; CHECK-LABEL: @test8
|
||||
; CHECK-NEXT: %A = mul i32 %X, %Y
|
||||
; CHECK-NEXT: %A = mul i32 %Y, %X
|
||||
; CHECK-NEXT: %C = sub i32 %Z, %A
|
||||
; CHECK-NEXT: ret i32 %C
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ define double @test3(double %x, double %y) {
|
||||
define i64 @test4(i64 %x, i64 %y) {
|
||||
; CHECK-LABEL: @test4
|
||||
; CHECK-NEXT: mul i64 %y, 1234
|
||||
; CHECK-NEXT: add i64 %x, %mul
|
||||
; CHECK-NEXT: add i64 %mul, %x
|
||||
; CHECK-NEXT: ret i64 %sub
|
||||
|
||||
%mul = mul i64 %y, -1234
|
||||
|
@ -4,8 +4,8 @@ declare void @use(i32)
|
||||
|
||||
define void @test1(i32 %x, i32 %y) {
|
||||
; CHECK-LABEL: test1
|
||||
; CHECK: mul i32 %x, %y
|
||||
; CHECK: mul i32 %x, %y
|
||||
; CHECK: mul i32 %y, %x
|
||||
; CHECK: mul i32 %y, %x
|
||||
; CHECK: sub i32 %1, %2
|
||||
; CHECK: call void @use(i32 %{{.*}})
|
||||
; CHECK: call void @use(i32 %{{.*}})
|
||||
|
@ -49,8 +49,8 @@ define float @test3(float %A, float %B, float %C, float %D) {
|
||||
; 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: %A.neg = fsub fast float -0.000000e+00, %A
|
||||
; CHECK-NEXT: %O.neg = fsub fast float %A.neg, %B
|
||||
; CHECK-NEXT: %B.neg = fsub fast float -0.000000e+00, %B
|
||||
; CHECK-NEXT: %O.neg = fsub fast float %B.neg, %A
|
||||
; CHECK-NEXT: %P = fsub fast float %O.neg, %C
|
||||
; CHECK-NEXT: %Q = fadd fast float %P, %D
|
||||
; CHECK-NEXT: ret float %Q
|
||||
|
@ -26,7 +26,7 @@ define float @test2(float %reg109, float %reg1111) {
|
||||
|
||||
define float @test3(float %reg109, float %reg1111) {
|
||||
; CHECK-LABEL: @test3
|
||||
; CHECK-NEXT: %reg117 = fadd fast float %reg1111, %reg109
|
||||
; CHECK-NEXT: %reg117 = fadd fast float %reg109, %reg1111
|
||||
; CHECK-NEXT: ret float %reg117
|
||||
|
||||
%reg115 = fadd fast float %reg109, -3.000000e+01
|
||||
@ -106,7 +106,7 @@ define void @test6() {
|
||||
|
||||
define float @test7(float %A, float %B, float %C) {
|
||||
; CHECK-LABEL: @test7
|
||||
; CHECK-NEXT: fadd fast float %B, %C
|
||||
; CHECK-NEXT: fadd fast float %C, %B
|
||||
; CHECK-NEXT: fmul fast float %A, %A
|
||||
; CHECK-NEXT: fmul fast float %1, %tmp2
|
||||
; CHECK-NEXT: ret float
|
||||
@ -121,7 +121,7 @@ define float @test7(float %A, float %B, float %C) {
|
||||
|
||||
define float @test8(float %X, float %Y, float %Z) {
|
||||
; CHECK-LABEL: @test8
|
||||
; CHECK-NEXT: fmul fast float %X, %Y
|
||||
; CHECK-NEXT: fmul fast float %Y, %X
|
||||
; CHECK-NEXT: fsub fast float %Z
|
||||
; CHECK-NEXT: ret float
|
||||
|
||||
@ -269,8 +269,8 @@ define float @test19(float %A, float %B) {
|
||||
; 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, %c
|
||||
; CHECK-NEXT: fsub fast float %c.neg, %b
|
||||
; 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
|
||||
|
@ -4,8 +4,8 @@ declare void @use(float)
|
||||
|
||||
define void @test1(float %x, float %y) {
|
||||
; CHECK-LABEL: test1
|
||||
; CHECK: fmul fast float %x, %y
|
||||
; CHECK: fmul fast float %x, %y
|
||||
; CHECK: fmul fast float %y, %x
|
||||
; CHECK: fmul fast float %y, %x
|
||||
; CHECK: fsub fast float %1, %2
|
||||
; CHECK: call void @use(float %{{.*}})
|
||||
; CHECK: call void @use(float %{{.*}})
|
||||
@ -20,8 +20,8 @@ define void @test1(float %x, float %y) {
|
||||
|
||||
define float @test2(float %x, float %y) {
|
||||
; CHECK-LABEL: test2
|
||||
; CHECK-NEXT: fmul fast float %x, %y
|
||||
; CHECK-NEXT: fmul fast float %x, %y
|
||||
; CHECK-NEXT: fmul fast float %y, %x
|
||||
; CHECK-NEXT: fmul fast float %y, %x
|
||||
; CHECK-NEXT: fsub fast float %1, %2
|
||||
; CHECK-NEXT: ret float %3
|
||||
|
||||
@ -33,8 +33,8 @@ define float @test2(float %x, float %y) {
|
||||
|
||||
define float @test3(float %x, float %y) {
|
||||
; CHECK-LABEL: test3
|
||||
; CHECK-NEXT: %factor = fmul fast float %x, 2.000000e+00
|
||||
; CHECK-NEXT: %tmp1 = fmul fast float %factor, %y
|
||||
; CHECK-NEXT: %factor = fmul fast float %y, 2.000000e+00
|
||||
; CHECK-NEXT: %tmp1 = fmul fast float %factor, %x
|
||||
; CHECK-NEXT: ret float %tmp1
|
||||
|
||||
%1 = fmul fast float %x, %y
|
||||
|
@ -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 %b, %c
|
||||
; CHECK-NEXT: fadd fast float %c, %b
|
||||
; CHECK-NEXT: fmul fast float %a, %tmp2
|
||||
; CHECK-NEXT: fmul fast float %a, %tmp3
|
||||
; CHECK-NEXT: fmul fast float %tmp3, %a
|
||||
; CHECK-NEXT: ret float
|
||||
|
||||
%t0 = fmul fast float %a, %b
|
||||
@ -19,9 +19,9 @@ define float @fmultistep1(float %a, float %b, float %c) {
|
||||
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 %b, %c
|
||||
; CHECK-NEXT: fmul fast float %a, %tmp
|
||||
; CHECK-NEXT: fadd fast float %d, %tmp1
|
||||
; 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
|
||||
|
||||
%t0 = fmul fast float %a, %b
|
||||
|
@ -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 %b, %factor
|
||||
; CHECK-NEXT: fmul fast float %a, %tmp1
|
||||
; CHECK-NEXT: fadd fast float %mul3, %tmp2
|
||||
; CHECK-NEXT: fadd fast float %factor, %b
|
||||
; CHECK-NEXT: fmul fast float %tmp1, %a
|
||||
; CHECK-NEXT: fadd fast float %tmp2, %mul3
|
||||
; CHECK-NEXT: ret float
|
||||
%mul1 = fmul fast float %a, %c
|
||||
%mul2 = fmul fast float %a, %b
|
||||
|
@ -8,9 +8,9 @@ define i64 @multistep1(i64 %a, i64 %b, i64 %c) {
|
||||
%t2 = mul i64 %a, %c
|
||||
%t3 = mul i64 %a, %t2 ; a*(a*c)
|
||||
%t4 = add i64 %t1, %t3
|
||||
; CHECK-NEXT: add i64 %b, %c
|
||||
; CHECK-NEXT: mul i64 %a, %tmp{{.*}}
|
||||
; CHECK-NEXT: add i64 %c, %b
|
||||
; CHECK-NEXT: mul i64 %a, %tmp{{.*}}
|
||||
; CHECK-NEXT: mul i64 %tmp{{.*}}, %a
|
||||
; CHECK-NEXT: ret
|
||||
ret i64 %t4
|
||||
}
|
||||
@ -22,9 +22,9 @@ define i64 @multistep2(i64 %a, i64 %b, i64 %c, i64 %d) {
|
||||
%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 %b, %c
|
||||
; CHECK-NEXT: mul i64 %a, %tmp{{.*}}
|
||||
; CHECK-NEXT: add i64 %d, %tmp{{.*}}
|
||||
; CHECK-NEXT: add i64 %c, %b
|
||||
; CHECK-NEXT: mul i64 %tmp{{.*}}, %a
|
||||
; CHECK-NEXT: add i64 %tmp{{.*}}, %d
|
||||
; CHECK-NEXT: ret
|
||||
ret i64 %t3
|
||||
}
|
||||
|
@ -27,11 +27,11 @@ define void @test2(i32 %a, i32 %b, i32 %c, i32 %d) {
|
||||
; 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 %a, %b
|
||||
; CHECK-NEXT: %a0 = add nsw i32 %b, %a
|
||||
%a1 = add nsw i32 %a0, %d
|
||||
; CHECK-NEXT: %a1 = add i32 %a0, %c
|
||||
%a2 = add nsw i32 %a1, %c
|
||||
; CHECK-NEXT: %a2 = add i32 %d, %a1
|
||||
; CHECK-NEXT: %a2 = add i32 %a1, %d
|
||||
call void @use(i32 %a2)
|
||||
; CHECK-NEXT: call void @use
|
||||
ret void
|
||||
|
@ -1,29 +1,28 @@
|
||||
; RUN: opt -S -reassociate -dce < %s | FileCheck %s
|
||||
; RUN: opt -S -reassociate < %s | FileCheck %s
|
||||
; rdar://8944681
|
||||
|
||||
; Reassociate should clear optional flags like nsw when reassociating.
|
||||
|
||||
; CHECK-LABEL: @test0(
|
||||
; CHECK: %z = add i64 %b, 2
|
||||
define i64 @test0(i64 %a, i64 %b) {
|
||||
%x = add nsw i64 %a, 2
|
||||
%y = add nsw i64 %x, %b
|
||||
%z = sub nsw i64 %y, %a
|
||||
; CHECK: %y = add i64 %b, %a
|
||||
; CHECK: %z = add i64 %y, %c
|
||||
define i64 @test0(i64 %a, i64 %b, i64 %c) {
|
||||
%y = add nsw i64 %c, %b
|
||||
%z = add i64 %y, %a
|
||||
ret i64 %z
|
||||
}
|
||||
|
||||
; CHECK-LABEL: @test1(
|
||||
; CHECK: %y = mul i64 %a, 6
|
||||
; CHECK: %z = sub nsw i64 %y, %a
|
||||
define i64 @test1(i64 %a, i64 %b) {
|
||||
%x = add nsw i64 %a, %a
|
||||
%y = mul nsw i64 %x, 3
|
||||
%z = sub nsw i64 %y, %a
|
||||
; CHECK: %y = add i64 %b, %a
|
||||
; CHECK: %z = add i64 %y, %c
|
||||
define i64 @test1(i64 %a, i64 %b, i64 %c) {
|
||||
%y = add i64 %c, %b
|
||||
%z = add nsw i64 %y, %a
|
||||
ret i64 %z
|
||||
}
|
||||
|
||||
; PR9215
|
||||
; CHECK: %s = add nsw i32 %x, %y
|
||||
; CHECK: %s = add nsw i32 %y, %x
|
||||
define i32 @test2(i32 %x, i32 %y) {
|
||||
%s = add nsw i32 %x, %y
|
||||
ret i32 %s
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define i32 @test1(i32 %X, i32 %Y) {
|
||||
; CHECK-LABEL: test1
|
||||
; CHECK-NEXT: %tmp = add i32 %X, %Y
|
||||
; CHECK-NEXT: %tmp = add i32 %Y, %X
|
||||
; CHECK-NEXT: %tmp1 = shl i32 %tmp, 1
|
||||
; CHECK-NEXT: ret i32 %tmp1
|
||||
|
||||
|
@ -15,7 +15,7 @@ define i32 @test1(i32 %A, i32 %B) {
|
||||
; 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 %b, %c
|
||||
; CHECK-NEXT: %sum = add i32 %c, %b
|
||||
; CHECK-NEXT: %tmp7 = sub i32 0, %sum
|
||||
; CHECK-NEXT: ret i32 %tmp7
|
||||
|
||||
|
@ -45,7 +45,7 @@ define i32 @xor3(i32 %x, i32 %y) {
|
||||
;CHECK-LABEL: @xor3(
|
||||
;CHECK: %and.ra = and i32 %x, -436
|
||||
;CHECK: %xor = xor i32 %y, 123
|
||||
;CHECK: %xor1 = xor i32 %and.ra, %xor
|
||||
;CHECK: %xor1 = xor i32 %xor, %and.ra
|
||||
}
|
||||
|
||||
; Test rule: (x | c1) ^ c2 = (x & ~c1) ^ (c1 ^ c2)
|
||||
@ -57,7 +57,7 @@ define i32 @xor4(i32 %x, i32 %y) {
|
||||
; CHECK-LABEL: @xor4(
|
||||
; CHECK: %and = and i32 %x, -124
|
||||
; CHECK: %xor = xor i32 %y, 435
|
||||
; CHECK: %xor1 = xor i32 %and, %xor
|
||||
; CHECK: %xor1 = xor i32 %xor, %and
|
||||
}
|
||||
|
||||
; ==========================================================================
|
||||
@ -89,7 +89,7 @@ define i32 @xor_special2(i32 %x, i32 %y) {
|
||||
ret i32 %xor1
|
||||
; CHECK-LABEL: @xor_special2(
|
||||
; CHECK: %xor = xor i32 %y, 123
|
||||
; CHECK: %xor1 = xor i32 %x, %xor
|
||||
; CHECK: %xor1 = xor i32 %xor, %x
|
||||
; CHECK: ret i32 %xor1
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user