File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -1857,13 +1857,22 @@ static Instruction *foldFNegIntoConstant(Instruction &I) {
1857
1857
}
1858
1858
1859
1859
Instruction *InstCombiner::visitFNeg (UnaryOperator &I) {
1860
- if (Value *V = SimplifyFNegInst (I.getOperand (0 ), I.getFastMathFlags (),
1860
+ Value *Op = I.getOperand (0 );
1861
+
1862
+ if (Value *V = SimplifyFNegInst (Op, I.getFastMathFlags (),
1861
1863
SQ.getWithInstruction (&I)))
1862
1864
return replaceInstUsesWith (I, V);
1863
1865
1864
1866
if (Instruction *X = foldFNegIntoConstant (I))
1865
1867
return X;
1866
1868
1869
+ Value *X, *Y;
1870
+
1871
+ // If we can ignore the sign of zeros: -(X - Y) --> (Y - X)
1872
+ if (I.hasNoSignedZeros () &&
1873
+ match (Op, m_OneUse (m_FSub (m_Value (X), m_Value (Y)))))
1874
+ return BinaryOperator::CreateFSubFMF (Y, X, &I);
1875
+
1867
1876
return nullptr ;
1868
1877
}
1869
1878
Original file line number Diff line number Diff line change @@ -38,11 +38,9 @@ define float @neg_sub_nsz(float %x, float %y) {
38
38
ret float %t2
39
39
}
40
40
41
- ; FIXME: This combine isn't working.
42
41
define float @unary_neg_sub_nsz (float %x , float %y ) {
43
42
; CHECK-LABEL: @unary_neg_sub_nsz(
44
- ; CHECK-NEXT: [[T1:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
45
- ; CHECK-NEXT: [[T2:%.*]] = fneg nsz float [[T1]]
43
+ ; CHECK-NEXT: [[T2:%.*]] = fsub nsz float [[Y:%.*]], [[X:%.*]]
46
44
; CHECK-NEXT: ret float [[T2]]
47
45
;
48
46
%t1 = fsub float %x , %y
You can’t perform that action at this time.
0 commit comments