mirror of
https://github.com/RPCS3/llvm.git
synced 2025-03-06 09:39:28 +00:00
[Reassociate] Canonicalize negative constants out of expressions.
Add support for FDiv, which was regressed by the previous commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221738 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a03cda02ab
commit
7ad8db4cbb
@ -1955,7 +1955,8 @@ Instruction *Reassociate::canonicalizeNegConstExpr(Instruction *I) {
|
||||
|
||||
// Must be a mul instruction.
|
||||
unsigned Opcode = I->getOpcode();
|
||||
if (Opcode != Instruction::Mul && Opcode != Instruction::FMul)
|
||||
if (Opcode != Instruction::Mul && Opcode != Instruction::FMul &&
|
||||
Opcode != Instruction::FDiv)
|
||||
return nullptr;
|
||||
|
||||
// Must have at least one constant operand.
|
||||
|
@ -108,3 +108,51 @@ define double @test8(double %x, double %y) {
|
||||
%add = fadd double %mul, %x
|
||||
ret double %add
|
||||
}
|
||||
|
||||
; Canonicalize (x - -0.1234 / y)
|
||||
define double @test9(double %x, double %y) {
|
||||
; CHECK-LABEL: @test9
|
||||
; CHECK-NEXT: fdiv double 1.234000e-01, %y
|
||||
; CHECK-NEXT: fadd double %x, %div
|
||||
; CHECK-NEXT: ret double
|
||||
|
||||
%div = fdiv double -1.234000e-01, %y
|
||||
%sub = fsub double %x, %div
|
||||
ret double %sub
|
||||
}
|
||||
|
||||
; Don't modify (-0.1234 / y - x)
|
||||
define double @test10(double %x, double %y) {
|
||||
; CHECK-LABEL: @test10
|
||||
; CHECK-NEXT: fdiv double -1.234000e-01, %y
|
||||
; CHECK-NEXT: fsub double %div, %x
|
||||
; CHECK-NEXT: ret double %sub
|
||||
|
||||
%div = fdiv double -1.234000e-01, %y
|
||||
%sub = fsub double %div, %x
|
||||
ret double %sub
|
||||
}
|
||||
|
||||
; Canonicalize (-0.1234 / y + x) -> (x - 0.1234 / y)
|
||||
define double @test11(double %x, double %y) {
|
||||
; CHECK-LABEL: @test11
|
||||
; CHECK-NEXT: fdiv double 1.234000e-01, %y
|
||||
; CHECK-NEXT: fsub double %x, %div
|
||||
; CHECK-NEXT: ret double %add
|
||||
|
||||
%div = fdiv double -1.234000e-01, %y
|
||||
%add = fadd double %div, %x
|
||||
ret double %add
|
||||
}
|
||||
|
||||
; Canonicalize (y / -0.1234 + x) -> (x - y / 0.1234)
|
||||
define double @test12(double %x, double %y) {
|
||||
; CHECK-LABEL: @test12
|
||||
; CHECK-NEXT: fdiv double %y, 1.234000e-01
|
||||
; CHECK-NEXT: fsub double %x, %div
|
||||
; CHECK-NEXT: ret double %add
|
||||
|
||||
%div = fdiv double %y, -1.234000e-01
|
||||
%add = fadd double %div, %x
|
||||
ret double %add
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user