1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

[InstCombine] check uses before creating instructions for fmul distribution

As the tests show, we could create extra instructions without any obvious benefit.

llvm-svn: 328498
This commit is contained in:
Sanjay Patel 2018-03-26 14:25:43 +00:00
parent 726b2ad8ca
commit 4eeecd6b13
2 changed files with 4 additions and 13 deletions

View File

@ -581,7 +581,7 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
// X * C, C/X, X/C, where C is a constant.
// (MDC +/- C1) * C => (MDC * C) +/- (C1 * C)
Instruction *FAddSub = dyn_cast<Instruction>(Op0);
if (FAddSub &&
if (FAddSub && FAddSub->hasOneUse() &&
(FAddSub->getOpcode() == Instruction::FAdd ||
FAddSub->getOpcode() == Instruction::FSub)) {
Value *Opnd0 = FAddSub->getOperand(0);

View File

@ -495,14 +495,11 @@ define float @fmul_fadd_fmul_distribute(float %x) {
ret float %t3
}
; FIXME: More instructions than we started with.
define float @fmul_fadd_distribute_extra_use(float %x) {
; CHECK-LABEL: @fmul_fadd_distribute_extra_use(
; CHECK-NEXT: [[T1:%.*]] = fmul float [[X:%.*]], 6.000000e+00
; CHECK-NEXT: [[T2:%.*]] = fadd float [[T1]], 2.000000e+00
; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], 3.000000e+01
; CHECK-NEXT: [[T3:%.*]] = fadd fast float [[TMP1]], 1.000000e+01
; CHECK-NEXT: [[T3:%.*]] = fmul fast float [[T2]], 5.000000e+00
; CHECK-NEXT: call void @use_f32(float [[T2]])
; CHECK-NEXT: ret float [[T3]]
;
@ -559,14 +556,11 @@ define float @fmul_fsub_fmul_distribute(float %x) {
ret float %t3
}
; FIXME: More instructions than we started with.
define float @fmul_fsub_fmul_distribute_extra_use(float %x) {
; CHECK-LABEL: @fmul_fsub_fmul_distribute_extra_use(
; CHECK-NEXT: [[T1:%.*]] = fmul float [[X:%.*]], 6.000000e+00
; CHECK-NEXT: [[T2:%.*]] = fsub float 2.000000e+00, [[T1]]
; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], 3.000000e+01
; CHECK-NEXT: [[T3:%.*]] = fsub fast float 1.000000e+01, [[TMP1]]
; CHECK-NEXT: [[T3:%.*]] = fmul fast float [[T2]], 5.000000e+00
; CHECK-NEXT: call void @use_f32(float [[T2]])
; CHECK-NEXT: ret float [[T3]]
;
@ -591,14 +585,11 @@ define float @fmul_fsub_fmul_distribute2(float %x) {
ret float %t3
}
; FIXME: More instructions than we started with.
define float @fmul_fsub_fmul_distribute2_extra_use(float %x) {
; CHECK-LABEL: @fmul_fsub_fmul_distribute2_extra_use(
; CHECK-NEXT: [[T1:%.*]] = fmul float [[X:%.*]], 6.000000e+00
; CHECK-NEXT: [[T2:%.*]] = fsub float 2.000000e+00, [[T1]]
; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], 3.000000e+01
; CHECK-NEXT: [[T3:%.*]] = fsub fast float 1.000000e+01, [[TMP1]]
; CHECK-NEXT: [[T3:%.*]] = fmul fast float [[T2]], 5.000000e+00
; CHECK-NEXT: call void @use_f32(float [[T2]])
; CHECK-NEXT: ret float [[T3]]
;