mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 23:32:27 +00:00
[Reassociate] Canonicalize constants to RHS operand.
Fix a thinko where the RHS was already a constant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222139 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6e61dd242b
commit
ae3738f4a7
@ -332,6 +332,7 @@ unsigned Reassociate::getRank(Value *V) {
|
|||||||
return ValueRankMap[I] = Rank;
|
return ValueRankMap[I] = Rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Canonicalize constants to RHS. Otherwise, sort the operands by rank.
|
||||||
void Reassociate::canonicalizeOperands(Instruction *I) {
|
void Reassociate::canonicalizeOperands(Instruction *I) {
|
||||||
assert(isa<BinaryOperator>(I) && "Expected binary operator.");
|
assert(isa<BinaryOperator>(I) && "Expected binary operator.");
|
||||||
assert(I->isCommutative() && "Expected commutative operator.");
|
assert(I->isCommutative() && "Expected commutative operator.");
|
||||||
@ -341,7 +342,9 @@ void Reassociate::canonicalizeOperands(Instruction *I) {
|
|||||||
unsigned LHSRank = getRank(LHS);
|
unsigned LHSRank = getRank(LHS);
|
||||||
unsigned RHSRank = getRank(RHS);
|
unsigned RHSRank = getRank(RHS);
|
||||||
|
|
||||||
// Canonicalize constants to RHS. Otherwise, sort the operands by rank.
|
if (isa<Constant>(RHS))
|
||||||
|
return;
|
||||||
|
|
||||||
if (isa<Constant>(LHS) || RHSRank < LHSRank)
|
if (isa<Constant>(LHS) || RHSRank < LHSRank)
|
||||||
cast<BinaryOperator>(I)->swapOperands();
|
cast<BinaryOperator>(I)->swapOperands();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ define double @test1(double %x, double %y) {
|
|||||||
; (x + -0.1234 * y) * (x + -0.1234 * y) -> (x - 0.1234 * y) * (x - 0.1234 * y)
|
; (x + -0.1234 * y) * (x + -0.1234 * y) -> (x - 0.1234 * y) * (x - 0.1234 * y)
|
||||||
define double @test2(double %x, double %y) {
|
define double @test2(double %x, double %y) {
|
||||||
; CHECK-LABEL: @test2
|
; CHECK-LABEL: @test2
|
||||||
; CHECK-NEXT: fmul double 1.234000e-01, %y
|
; CHECK-NEXT: fmul double %y, 1.234000e-01
|
||||||
; CHECK-NEXT: fsub double %x, %mul
|
; CHECK-NEXT: fsub double %x, %mul
|
||||||
; CHECK-NEXT: fmul double %add{{.*}}, %add{{.*}}
|
; CHECK-NEXT: fmul double %add{{.*}}, %add{{.*}}
|
||||||
; CHECK-NEXT: ret double %mul
|
; CHECK-NEXT: ret double %mul
|
||||||
@ -36,7 +36,7 @@ define double @test2(double %x, double %y) {
|
|||||||
; (x + 0.1234 * y) * (x - -0.1234 * y) -> (x + 0.1234 * y) * (x + 0.1234 * y)
|
; (x + 0.1234 * y) * (x - -0.1234 * y) -> (x + 0.1234 * y) * (x + 0.1234 * y)
|
||||||
define double @test3(double %x, double %y) {
|
define double @test3(double %x, double %y) {
|
||||||
; CHECK-LABEL: @test3
|
; CHECK-LABEL: @test3
|
||||||
; CHECK-NEXT: fmul double 1.234000e-01, %y
|
; CHECK-NEXT: fmul double %y, 1.234000e-01
|
||||||
; CHECK-NEXT: fadd double %x, %mul
|
; CHECK-NEXT: fadd double %x, %mul
|
||||||
; CHECK-NEXT: fmul double %add{{.*}}, %add{{.*}}
|
; CHECK-NEXT: fmul double %add{{.*}}, %add{{.*}}
|
||||||
; CHECK-NEXT: ret double
|
; CHECK-NEXT: ret double
|
||||||
@ -100,7 +100,7 @@ define double @test7(double %x, double %y) {
|
|||||||
; Canonicalize (y * -0.1234 + x) -> (x - 0.1234 * y)
|
; Canonicalize (y * -0.1234 + x) -> (x - 0.1234 * y)
|
||||||
define double @test8(double %x, double %y) {
|
define double @test8(double %x, double %y) {
|
||||||
; CHECK-LABEL: @test8
|
; CHECK-LABEL: @test8
|
||||||
; CHECK-NEXT: fmul double 1.234000e-01, %y
|
; CHECK-NEXT: fmul double %y, 1.234000e-01
|
||||||
; CHECK-NEXT: fsub double %x, %mul
|
; CHECK-NEXT: fsub double %x, %mul
|
||||||
; CHECK-NEXT: ret double %add
|
; CHECK-NEXT: ret double %add
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
define float @test1(float %A) {
|
define float @test1(float %A) {
|
||||||
; CHECK-LABEL: test1
|
; CHECK-LABEL: test1
|
||||||
; CHECK-NEXT: %X = fadd float 1.000000e+00, %A
|
; CHECK-NEXT: %X = fadd float %A, 1.000000e+00
|
||||||
; CHECK-NEXT: %Y = fadd float 1.000000e+00, %A
|
; CHECK-NEXT: %Y = fadd float %A, 1.000000e+00
|
||||||
; CHECK-NEXT: %r = fsub float %X, %Y
|
; CHECK-NEXT: %r = fsub float %X, %Y
|
||||||
; CHECK-NEXT: ret float %r
|
; CHECK-NEXT: ret float %r
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ 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 2.000000e+00, %y
|
; CHECK-NEXT: %factor = fmul fast float %y, 2.000000e+00
|
||||||
; CHECK-NEXT: %tmp1 = fmul fast float %factor, %x
|
; CHECK-NEXT: %tmp1 = fmul fast float %factor, %x
|
||||||
; CHECK-NEXT: ret float %tmp1
|
; CHECK-NEXT: ret float %tmp1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user