Skip to content

Commit f1f510c

Browse files
committed
[InstCombine] Add more tests. NFC.
1 parent cb419c7 commit f1f510c

File tree

1 file changed

+88
-10
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+88
-10
lines changed

llvm/test/Transforms/InstCombine/fabs.ll

Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,35 +1329,53 @@ define float @test_fabs_fsub_used_by_fpop_nnan(float %x, float %y) {
13291329
ret float %add
13301330
}
13311331

1332-
; Negative tests
1333-
1334-
define float @test_fabs_used_by_fpop_nnan(float %x, float %y) {
1335-
; CHECK-LABEL: @test_fabs_used_by_fpop_nnan(
1332+
; TODO: fadd ignores the sign bit of NaN.
1333+
define float @test_fabs_used_by_fpop_nsz(float %x, float %y) {
1334+
; CHECK-LABEL: @test_fabs_used_by_fpop_nsz(
13361335
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[X:%.*]], 0.000000e+00
13371336
; CHECK-NEXT: [[NEG:%.*]] = fneg float [[X]]
13381337
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], float [[X]], float [[NEG]]
1339-
; CHECK-NEXT: [[ADD:%.*]] = fadd nnan float [[SEL]], [[Y:%.*]]
1338+
; CHECK-NEXT: [[ADD:%.*]] = fadd nsz float [[SEL]], [[Y:%.*]]
13401339
; CHECK-NEXT: ret float [[ADD]]
13411340
;
13421341
%cmp = fcmp oge float %x, 0.000000e+00
13431342
%neg = fneg float %x
13441343
%sel = select i1 %cmp, float %x, float %neg
1345-
%add = fadd nnan float %sel, %y
1344+
%add = fadd nsz float %sel, %y
13461345
ret float %add
13471346
}
13481347

1349-
define float @test_fabs_used_by_fpop_nsz(float %x, float %y) {
1350-
; CHECK-LABEL: @test_fabs_used_by_fpop_nsz(
1348+
; TODO: copysign ignores the sign bit of NaN magnitude.
1349+
define float @test_fabs_used_by_fcopysign_mag(float %x, float %y) {
1350+
; CHECK-LABEL: @test_fabs_used_by_fcopysign_mag(
1351+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[X1:%.*]], 0.000000e+00
1352+
; CHECK-NEXT: [[NEG:%.*]] = fneg float [[X1]]
1353+
; CHECK-NEXT: [[X:%.*]] = select i1 [[CMP]], float [[X1]], float [[NEG]]
1354+
; CHECK-NEXT: [[COPYSIGN:%.*]] = call float @llvm.copysign.f32(float [[X]], float [[Y:%.*]])
1355+
; CHECK-NEXT: ret float [[COPYSIGN]]
1356+
;
1357+
%cmp = fcmp oge float %x, 0.000000e+00
1358+
%neg = fneg float %x
1359+
%sel = select i1 %cmp, float %x, float %neg
1360+
%copysign = call float @llvm.copysign.f32(float %sel, float %y)
1361+
ret float %copysign
1362+
}
1363+
1364+
1365+
; Negative tests
1366+
1367+
define float @test_fabs_used_by_fpop_nnan(float %x, float %y) {
1368+
; CHECK-LABEL: @test_fabs_used_by_fpop_nnan(
13511369
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[X:%.*]], 0.000000e+00
13521370
; CHECK-NEXT: [[NEG:%.*]] = fneg float [[X]]
13531371
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], float [[X]], float [[NEG]]
1354-
; CHECK-NEXT: [[ADD:%.*]] = fadd nsz float [[SEL]], [[Y:%.*]]
1372+
; CHECK-NEXT: [[ADD:%.*]] = fadd nnan float [[SEL]], [[Y:%.*]]
13551373
; CHECK-NEXT: ret float [[ADD]]
13561374
;
13571375
%cmp = fcmp oge float %x, 0.000000e+00
13581376
%neg = fneg float %x
13591377
%sel = select i1 %cmp, float %x, float %neg
1360-
%add = fadd nsz float %sel, %y
1378+
%add = fadd nnan float %sel, %y
13611379
ret float %add
13621380
}
13631381

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

0 commit comments

Comments
 (0)