Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 8e937c3

Browse files
committed
InstCombine: Make the (fmul X, -1.0) -> (fsub -0.0, X) transform handle vectors too.
PR18532. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199553 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent bedf842 commit 8e937c3

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,15 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
425425
if (Instruction *NV = FoldOpIntoPhi(I))
426426
return NV;
427427

428-
ConstantFP *C = dyn_cast<ConstantFP>(Op1);
429-
430428
// (fmul X, -1.0) --> (fsub -0.0, X)
431-
if (C && C->isExactlyValue(-1.0)) {
432-
Instruction *RI = BinaryOperator::CreateFSub(
433-
ConstantFP::getNegativeZero(C->getType()),
434-
Op0);
429+
if (match(Op1, m_SpecificFP(-1.0))) {
430+
Constant *NegZero = ConstantFP::getNegativeZero(Op1->getType());
431+
Instruction *RI = BinaryOperator::CreateFSub(NegZero, Op0);
435432
RI->copyFastMathFlags(&I);
436433
return RI;
437434
}
438435

436+
ConstantFP *C = dyn_cast<ConstantFP>(Op1);
439437
if (C && AllowReassociate && C->getValueAPF().isFiniteNonZero()) {
440438
// Let MDC denote an expression in one of these forms:
441439
// X * C, C/X, X/C, where C is a constant.

test/Transforms/InstCombine/fmul.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,12 @@ define float @test9(float %x) {
104104
; CHECK: fsub
105105
}
106106

107+
; PR18532
108+
define <4 x float> @test10(<4 x float> %x) {
109+
%mul = fmul <4 x float> %x, <float -1.0, float -1.0, float -1.0, float -1.0>
110+
ret <4 x float> %mul
111+
112+
; CHECK-LABEL: @test10(
113+
; CHECK-NOT: fmul
114+
; CHECK: fsub
115+
}

0 commit comments

Comments
 (0)