File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -2002,7 +2002,7 @@ Instruction *InstCombinerImpl::visitFAdd(BinaryOperator &I) {
20022002 if (Instruction *FoldedFAdd = foldBinOpIntoSelectOrPhi (I))
20032003 return FoldedFAdd;
20042004
2005- // B = fadd A, 0
2005+ // B = fadd A, 0.0
20062006 // Z = Op B
20072007 // can be transformed into
20082008 // Z = Op A
@@ -3125,6 +3125,16 @@ Instruction *InstCombinerImpl::visitFSub(BinaryOperator &I) {
31253125 Value *X, *Y;
31263126 Constant *C;
31273127
3128+ // B = fsub A, 0.0
3129+ // Z = Op B
3130+ // can be transformed into
3131+ // Z = Op A
3132+ // Where Op is such that we can ignore sign of 0 in fsub
3133+ Value *A;
3134+ if (match (&I, m_OneUse (m_FSub (m_Value (A), m_AnyZeroFP ()))) &&
3135+ canIgnoreSignBitOfZero (*I.use_begin ()))
3136+ return replaceInstUsesWith (I, A);
3137+
31283138 Value *Op0 = I.getOperand (0 ), *Op1 = I.getOperand (1 );
31293139 // If Op0 is not -0.0 or we can ignore -0.0: Z - (X - Y) --> Z + (Y - X)
31303140 // Canonicalize to fadd to make analysis easier.
Original file line number Diff line number Diff line change @@ -24,3 +24,14 @@ define float @src2(float %arg1) {
2424 %v4 = fsub float %v2 , %v3
2525 ret float %v4
2626}
27+
28+ define float @src_sub (float %arg1 ) {
29+ ; CHECK-LABEL: define float @src_sub(
30+ ; CHECK-SAME: float [[ARG1:%.*]]) {
31+ ; CHECK-NEXT: [[V3:%.*]] = call float @llvm.fabs.f32(float [[ARG1]])
32+ ; CHECK-NEXT: ret float [[V3]]
33+ ;
34+ %v2 = fsub float %arg1 , 0 .000000e+00
35+ %v3 = call float @llvm.fabs.f32 (float %v2 )
36+ ret float %v3
37+ }
You can’t perform that action at this time.
0 commit comments