Skip to content

Commit 201c339

Browse files
committed
Merge branch 'swift/main' of github.com:apple/llvm-project into swift/tensorflow-stage
* 'swift/main' of github.com:apple/llvm-project: [SelectionDAG] Don't remove unused negated constant immediately
2 parents 3700cdc + f29c2b2 commit 201c339

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5751,10 +5751,8 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
57515751

57525752
// If we already have the use of the negated floating constant, it is free
57535753
// to negate it even it has multiple uses.
5754-
if (!Op.hasOneUse() && CFP.use_empty()) {
5755-
RemoveDeadNode(CFP);
5754+
if (!Op.hasOneUse() && CFP.use_empty())
57565755
break;
5757-
}
57585756
Cost = NegatibleCost::Neutral;
57595757
return CFP;
57605758
}

llvm/test/CodeGen/X86/pr47517.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,16 @@ entry:
2626
%fmul6 = fmul fast float %fmul3, %fadd4
2727
ret float %fmul6
2828
}
29+
30+
; To ensure negated result will not be removed when NegX=NegY and
31+
; NegX is needed
32+
define float @test2(float %x, float %y) {
33+
%add = fadd fast float %x, 750.0
34+
%sub = fsub fast float %x, %add
35+
%mul = fmul fast float %sub, %sub
36+
%mul2 = fmul fast float %mul, %sub
37+
%add2 = fadd fast float %mul2, 1.0
38+
%add3 = fadd fast float %mul2, %add2
39+
%mul3 = fmul fast float %y, %add3
40+
ret float %mul3
41+
}

0 commit comments

Comments
 (0)