Teach InstCombine that (fmul X, -1.0) can be simplified to (fneg X), which LLVM expresses as (fsub -0.0, X).

llvm-svn: 199420
This commit is contained in:
Owen Anderson 2014-01-16 20:36:42 +00:00
parent 686738e226
commit f74cfe031f
2 changed files with 22 additions and 0 deletions

View File

@ -426,6 +426,16 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
return NV;
ConstantFP *C = dyn_cast<ConstantFP>(Op1);
// (fmul X, -1.0) --> (fsub -0.0, X)
if (C && C->isExactlyValue(-1.0)) {
Instruction *RI = BinaryOperator::CreateFSub(
ConstantFP::getNegativeZero(C->getType()),
Op0);
RI->copyFastMathFlags(&I);
return RI;
}
if (C && AllowReassociate && C->getValueAPF().isFiniteNonZero()) {
// Let MDC denote an expression in one of these forms:
// X * C, C/X, X/C, where C is a constant.

View File

@ -93,3 +93,15 @@ for.body: ; preds = %for.cond
for.end: ; preds = %for.cond
ret void
}
; X * -1.0 => -0.0 - X
define float @test9(float %x) {
%mul = fmul float %x, -1.0
ret float %mul
; CHECK-LABEL: @test9(
; CHECK-NOT: fmul
; CHECK: fsub
}