Skip to content

Commit 3eb71ff

Browse files
committed
[InstCombine] Add more tests. NFC.
1 parent 1b0fd5e commit 3eb71ff

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,12 +2835,15 @@ static bool ignoreSignBitOfNaN(Instruction &I) {
28352835
return true;
28362836
case Intrinsic::copysign:
28372837
return II->getArgOperand(0) == &I;
2838+
// fmin/fmax returns one of its operands, so the sign bit cannot be
2839+
// ignored.
28382840
case Intrinsic::maxnum:
28392841
case Intrinsic::minnum:
28402842
case Intrinsic::maximum:
28412843
case Intrinsic::minimum:
28422844
case Intrinsic::maximumnum:
28432845
case Intrinsic::minimumnum:
2846+
// llvm.canonicalize preserves the sign bit of NaN.
28442847
case Intrinsic::canonicalize:
28452848
return false;
28462849
default:

llvm/test/Transforms/InstCombine/fabs.ll

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,19 @@ define float @test_fabs_used_by_fpop_nsz(float %x, float %y) {
13421342
ret float %add
13431343
}
13441344

1345+
define float @test_fabs_used_by_fcopysign_mag(float %x, float %y) {
1346+
; CHECK-LABEL: @test_fabs_used_by_fcopysign_mag(
1347+
; CHECK-NEXT: [[COPYSIGN:%.*]] = call float @llvm.copysign.f32(float [[X:%.*]], float [[Y:%.*]])
1348+
; CHECK-NEXT: ret float [[COPYSIGN]]
1349+
;
1350+
%cmp = fcmp oge float %x, 0.000000e+00
1351+
%neg = fneg float %x
1352+
%sel = select i1 %cmp, float %x, float %neg
1353+
%copysign = call float @llvm.copysign.f32(float %sel, float %y)
1354+
ret float %copysign
1355+
}
1356+
1357+
13451358
; Negative tests
13461359

13471360
define float @test_fabs_used_by_fpop_nnan(float %x, float %y) {
@@ -1375,3 +1388,63 @@ define i1 @test_fabs_used_by_fcmp_multiuse(float %x, float %y) {
13751388
call void @use(float %sel)
13761389
ret i1 %cmp2
13771390
}
1391+
1392+
define float @test_fabs_used_by_fcopysign_sign(float %x, float %y) {
1393+
; CHECK-LABEL: @test_fabs_used_by_fcopysign_sign(
1394+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[X:%.*]], 0.000000e+00
1395+
; CHECK-NEXT: [[NEG:%.*]] = fneg float [[X]]
1396+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], float [[X]], float [[NEG]]
1397+
; CHECK-NEXT: [[COPYSIGN:%.*]] = call float @llvm.copysign.f32(float [[Y:%.*]], float [[SEL]])
1398+
; CHECK-NEXT: ret float [[COPYSIGN]]
1399+
;
1400+
%cmp = fcmp oge float %x, 0.000000e+00
1401+
%neg = fneg float %x
1402+
%sel = select i1 %cmp, float %x, float %neg
1403+
%copysign = call float @llvm.copysign.f32(float %y, float %sel)
1404+
ret float %copysign
1405+
}
1406+
1407+
define float @test_fabs_used_by_maxnum(float %x, float %y) {
1408+
; CHECK-LABEL: @test_fabs_used_by_maxnum(
1409+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[X:%.*]], 0.000000e+00
1410+
; CHECK-NEXT: [[NEG:%.*]] = fneg float [[X]]
1411+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], float [[X]], float [[NEG]]
1412+
; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[Y:%.*]], float [[SEL]])
1413+
; CHECK-NEXT: ret float [[MAX]]
1414+
;
1415+
%cmp = fcmp oge float %x, 0.000000e+00
1416+
%neg = fneg float %x
1417+
%sel = select i1 %cmp, float %x, float %neg
1418+
%max = call float @llvm.maxnum.f32(float %y, float %sel)
1419+
ret float %max
1420+
}
1421+
1422+
define float @test_fabs_used_by_canonicalize(float %x) {
1423+
; CHECK-LABEL: @test_fabs_used_by_canonicalize(
1424+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[X:%.*]], 0.000000e+00
1425+
; CHECK-NEXT: [[NEG:%.*]] = fneg float [[X]]
1426+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], float [[X]], float [[NEG]]
1427+
; CHECK-NEXT: [[CANON:%.*]] = call float @llvm.canonicalize.f32(float [[SEL]])
1428+
; CHECK-NEXT: ret float [[CANON]]
1429+
;
1430+
%cmp = fcmp oge float %x, 0.000000e+00
1431+
%neg = fneg float %x
1432+
%sel = select i1 %cmp, float %x, float %neg
1433+
%canon = call float @llvm.canonicalize.f32(float %sel)
1434+
ret float %canon
1435+
}
1436+
1437+
define float @test_fabs_used_by_select(float %x, i1 %cond) {
1438+
; CHECK-LABEL: @test_fabs_used_by_select(
1439+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[X:%.*]], 0.000000e+00
1440+
; CHECK-NEXT: [[NEG:%.*]] = fneg float [[X]]
1441+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], float [[X]], float [[NEG]]
1442+
; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[COND:%.*]], float [[SEL]], float 0.000000e+00
1443+
; CHECK-NEXT: ret float [[SEL2]]
1444+
;
1445+
%cmp = fcmp oge float %x, 0.000000e+00
1446+
%neg = fneg float %x
1447+
%sel = select i1 %cmp, float %x, float %neg
1448+
%sel2 = select i1 %cond, float %sel, float 0.000000e+00
1449+
ret float %sel2
1450+
}

0 commit comments

Comments
 (0)