Skip to content

Commit 486bbe7

Browse files
rework to check for a single use, and update the testcase
1 parent 717c2c8 commit 486bbe7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@ Instruction *InstCombinerImpl::visitFAdd(BinaryOperator &I) {
20082008
// Z = Op A
20092009
// Where Op is such that we can ignore sign of 0 in fadd
20102010
Value *A;
2011-
if (match(&I, m_c_FAdd(m_Value(A), m_AnyZeroFP())) && !I.use_empty() &&
2011+
if (match(&I, m_OneUse(m_c_FAdd(m_Value(A), m_AnyZeroFP()))) &&
20122012
canIgnoreSignBitOfZero(*I.use_begin()))
20132013
return replaceInstUsesWith(I, A);
20142014

llvm/test/Transforms/InstCombine/fold-fadd-with-zero-gh154238.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,17 @@ define float @src(float %arg1) {
1010
%v3 = call float @llvm.fabs.f32(float %v2)
1111
ret float %v3
1212
}
13+
14+
define float @src2(float %arg1) {
15+
; CHECK-LABEL: define float @src2(
16+
; CHECK-SAME: float [[ARG1:%.*]]) {
17+
; CHECK-NEXT: [[V2:%.*]] = fadd float [[ARG1]], 0.000000e+00
18+
; CHECK-NEXT: [[V3:%.*]] = call float @llvm.fabs.f32(float [[V2]])
19+
; CHECK-NEXT: [[V4:%.*]] = fsub float [[V2]], [[V3]]
20+
; CHECK-NEXT: ret float [[V4]]
21+
;
22+
%v2 = fadd float %arg1, 0.000000e+00
23+
%v3 = call float @llvm.fabs.f32(float %v2)
24+
%v4 = fsub float %v2, %v3
25+
ret float %v4
26+
}

0 commit comments

Comments
 (0)