132 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s3 4; Transform "a == C ? C : x" to "a == C ? a : x" to avoid materializing C.5define i32 @test1(i32 %x) {6; CHECK-LABEL: test1:7; CHECK: // %bb.0:8; CHECK-NEXT: mov w8, #79; CHECK-NEXT: cmp w0, #210; CHECK-NEXT: csel w0, w0, w8, eq11; CHECK-NEXT: ret12 %cmp = icmp eq i32 %x, 213 %res = select i1 %cmp, i32 2, i32 714 ret i32 %res15}16 17; Transform "a == C ? C : x" to "a == C ? a : x" to avoid materializing C.18define i64 @test2(i64 %x) {19; CHECK-LABEL: test2:20; CHECK: // %bb.0:21; CHECK-NEXT: mov w8, #722; CHECK-NEXT: cmp x0, #223; CHECK-NEXT: csel x0, x0, x8, eq24; CHECK-NEXT: ret25 %cmp = icmp eq i64 %x, 226 %res = select i1 %cmp, i64 2, i64 727 ret i64 %res28}29 30; Transform "a != C ? x : C" to "a != C ? x : a" to avoid materializing C.31define i64 @test3(i64 %x) {32; CHECK-LABEL: test3:33; CHECK: // %bb.0:34; CHECK-NEXT: mov w8, #235; CHECK-NEXT: cmp x0, #736; CHECK-NEXT: csel x0, x8, x0, ne37; CHECK-NEXT: ret38 %cmp = icmp ne i64 %x, 739 %res = select i1 %cmp, i64 2, i64 740 ret i64 %res41}42 43; Don't transform "a == C ? C : x" to "a == C ? a : x" if a == 0. If we did we44; would needlessly extend the live range of x0 when we can just use xzr.45define i64 @test4(i64 %x) {46; CHECK-LABEL: test4:47; CHECK: // %bb.0:48; CHECK-NEXT: mov w8, #749; CHECK-NEXT: cmp x0, #050; CHECK-NEXT: csel x0, xzr, x8, eq51; CHECK-NEXT: ret52 %cmp = icmp eq i64 %x, 053 %res = select i1 %cmp, i64 0, i64 754 ret i64 %res55}56 57; Don't transform "a == C ? C : x" to "a == C ? a : x" if a == 1. If we did we58; would needlessly extend the live range of x0 when we can just use xzr with59; CSINC to materialize the 1.60define i64 @test5(i64 %x) {61; CHECK-LABEL: test5:62; CHECK: // %bb.0:63; CHECK-NEXT: mov w8, #764; CHECK-NEXT: cmp x0, #165; CHECK-NEXT: csinc x0, x8, xzr, ne66; CHECK-NEXT: ret67 %cmp = icmp eq i64 %x, 168 %res = select i1 %cmp, i64 1, i64 769 ret i64 %res70}71 72; Don't transform "a == C ? C : x" to "a == C ? a : x" if a == -1. If we did we73; would needlessly extend the live range of x0 when we can just use xzr with74; CSINV to materialize the -1.75define i64 @test6(i64 %x) {76; CHECK-LABEL: test6:77; CHECK: // %bb.0:78; CHECK-NEXT: mov w8, #779; CHECK-NEXT: cmn x0, #180; CHECK-NEXT: csinv x0, x8, xzr, ne81; CHECK-NEXT: ret82 %cmp = icmp eq i64 %x, -183 %res = select i1 %cmp, i64 -1, i64 784 ret i64 %res85}86 87define i64 @test7(i64 %x) {88; CHECK-LABEL: test7:89; CHECK: // %bb.0:90; CHECK-NEXT: cmp x0, #791; CHECK-NEXT: csinc x0, x0, xzr, eq92; CHECK-NEXT: ret93 %cmp = icmp eq i64 %x, 794 %res = select i1 %cmp, i64 7, i64 195 ret i64 %res96}97 98define i64 @test8(i64 %x) {99; CHECK-LABEL: test8:100; CHECK: // %bb.0:101; CHECK-NEXT: cmp x0, #7102; CHECK-NEXT: csinc x0, x0, xzr, eq103; CHECK-NEXT: ret104 %cmp = icmp ne i64 %x, 7105 %res = select i1 %cmp, i64 1, i64 7106 ret i64 %res107}108 109define i64 @test9(i64 %x) {110; CHECK-LABEL: test9:111; CHECK: // %bb.0:112; CHECK-NEXT: cmp x0, #7113; CHECK-NEXT: csinv x0, x0, xzr, eq114; CHECK-NEXT: ret115 %cmp = icmp eq i64 %x, 7116 %res = select i1 %cmp, i64 7, i64 -1117 ret i64 %res118}119 120; Rather than use a CNEG, use a CSINV to transform "a == 1 ? 1 : -1" to121; "a == 1 ? a : -1" to avoid materializing a constant.122define i32 @test10(i32 %x) {123; CHECK-LABEL: test10:124; CHECK: // %bb.0:125; CHECK-NEXT: cmp w0, #1126; CHECK-NEXT: csinv w0, w0, wzr, eq127; CHECK-NEXT: ret128 %cmp = icmp eq i32 %x, 1129 %res = select i1 %cmp, i32 1, i32 -1130 ret i32 %res131}132