|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 |
| 2 | +; RUN: llc < %s -mtriple=aarch64-unknown-unknown | FileCheck %s |
| 3 | + |
| 4 | +define i64 @test_single_or(i64 %unrelated, i64 %x, i64 %y) nounwind { |
| 5 | +; CHECK-LABEL: test_single_or: |
| 6 | +; CHECK: // %bb.0: |
| 7 | +; CHECK-NEXT: cmp x2, x0 |
| 8 | +; CHECK-NEXT: sub x8, x2, x1 |
| 9 | +; CHECK-NEXT: ccmp x2, x1, #0, ls |
| 10 | +; CHECK-NEXT: csel x0, xzr, x8, lo |
| 11 | +; CHECK-NEXT: ret |
| 12 | + %cmp.match = icmp ult i64 %y, %x |
| 13 | + %cmp.nomatch = icmp ugt i64 %y, %unrelated |
| 14 | + %or.cond = or i1 %cmp.match, %cmp.nomatch |
| 15 | + %sub.reuse = sub nuw i64 %y, %x |
| 16 | + %res = select i1 %or.cond, i64 0, i64 %sub.reuse |
| 17 | + ret i64 %res |
| 18 | +} |
| 19 | + |
| 20 | +define i64 @test_two_ors(i64 %unrelated, i64 %x, i64 %y) nounwind { |
| 21 | +; CHECK-LABEL: test_two_ors: |
| 22 | +; CHECK: // %bb.0: |
| 23 | +; CHECK-NEXT: cmp x2, x0 |
| 24 | +; CHECK-NEXT: sub x8, x2, x1 |
| 25 | +; CHECK-NEXT: ccmp x2, x1, #0, ls |
| 26 | +; CHECK-NEXT: ccmp x0, x1, #0, hs |
| 27 | +; CHECK-NEXT: csel x0, xzr, x8, lo |
| 28 | +; CHECK-NEXT: ret |
| 29 | + %cmp.match = icmp ult i64 %y, %x |
| 30 | + %cmp.nomatch1 = icmp ult i64 %unrelated, %x |
| 31 | + %cmp.nomatch2 = icmp ugt i64 %y, %unrelated |
| 32 | + %or.nomatch = or i1 %cmp.nomatch1, %cmp.nomatch2 |
| 33 | + %or.cond = or i1 %cmp.match, %or.nomatch |
| 34 | + %sub.reuse = sub nuw i64 %y, %x |
| 35 | + %res = select i1 %or.cond, i64 0, i64 %sub.reuse |
| 36 | + ret i64 %res |
| 37 | +} |
| 38 | + |
| 39 | +define i64 @test_two_ors_commuted(i64 %unrelated, i64 %x, i64 %y) nounwind { |
| 40 | +; CHECK-LABEL: test_two_ors_commuted: |
| 41 | +; CHECK: // %bb.0: |
| 42 | +; CHECK-NEXT: cmp x2, x0 |
| 43 | +; CHECK-NEXT: sub x8, x2, x1 |
| 44 | +; CHECK-NEXT: ccmp x2, x1, #0, ls |
| 45 | +; CHECK-NEXT: ccmp x0, x1, #0, hs |
| 46 | +; CHECK-NEXT: csel x0, xzr, x8, lo |
| 47 | +; CHECK-NEXT: ret |
| 48 | + %cmp.match = icmp ult i64 %y, %x |
| 49 | + %cmp.nomatch1 = icmp ult i64 %unrelated, %x |
| 50 | + %cmp.nomatch2 = icmp ugt i64 %y, %unrelated |
| 51 | + %or.nomatch = or i1 %cmp.nomatch1, %cmp.nomatch2 |
| 52 | + %or.cond = or i1 %or.nomatch, %cmp.match |
| 53 | + %sub.reuse = sub nuw i64 %y, %x |
| 54 | + %res = select i1 %or.cond, i64 0, i64 %sub.reuse |
| 55 | + ret i64 %res |
| 56 | +} |
| 57 | + |
| 58 | +define i64 @test_single_and(i64 %unrelated, i64 %x, i64 %y) nounwind { |
| 59 | +; CHECK-LABEL: test_single_and: |
| 60 | +; CHECK: // %bb.0: |
| 61 | +; CHECK-NEXT: cmp x2, x0 |
| 62 | +; CHECK-NEXT: sub x8, x2, x1 |
| 63 | +; CHECK-NEXT: ccmp x2, x1, #2, hi |
| 64 | +; CHECK-NEXT: csel x0, xzr, x8, lo |
| 65 | +; CHECK-NEXT: ret |
| 66 | + %cmp.match = icmp ult i64 %y, %x |
| 67 | + %cmp.nomatch = icmp ugt i64 %y, %unrelated |
| 68 | + %and.cond = and i1 %cmp.match, %cmp.nomatch |
| 69 | + %sub.reuse = sub nuw i64 %y, %x |
| 70 | + %res = select i1 %and.cond, i64 0, i64 %sub.reuse |
| 71 | + ret i64 %res |
| 72 | +} |
| 73 | + |
| 74 | +define i64 @test_single_or_sub_commuted(i64 %unrelated, i64 %x, i64 %y) nounwind { |
| 75 | +; CHECK-LABEL: test_single_or_sub_commuted: |
| 76 | +; CHECK: // %bb.0: |
| 77 | +; CHECK-NEXT: cmp x2, x0 |
| 78 | +; CHECK-NEXT: sub x8, x1, x2 |
| 79 | +; CHECK-NEXT: ccmp x1, x2, #2, ls |
| 80 | +; CHECK-NEXT: csel x0, xzr, x8, hi |
| 81 | +; CHECK-NEXT: ret |
| 82 | + %cmp.match = icmp ult i64 %y, %x |
| 83 | + %cmp.nomatch = icmp ugt i64 %y, %unrelated |
| 84 | + %or.cond = or i1 %cmp.match, %cmp.nomatch |
| 85 | + %sub.reuse = sub nuw i64 %x, %y |
| 86 | + %res = select i1 %or.cond, i64 0, i64 %sub.reuse |
| 87 | + ret i64 %res |
| 88 | +} |
| 89 | + |
| 90 | +; Negative test: We must negate the or operation, hence this must come first. |
| 91 | +define i64 @test_mustbefirst_overrides_preferfirst_negative(i64 %unrelated, i64 %x, i64 %y) nounwind { |
| 92 | +; CHECK-LABEL: test_mustbefirst_overrides_preferfirst_negative: |
| 93 | +; CHECK: // %bb.0: |
| 94 | +; CHECK-NEXT: cmp x2, x0 |
| 95 | +; CHECK-NEXT: sub x8, x2, x1 |
| 96 | +; CHECK-NEXT: ccmp x0, x1, #0, ls |
| 97 | +; CHECK-NEXT: ccmp x2, x1, #2, lo |
| 98 | +; CHECK-NEXT: csel x0, xzr, x8, lo |
| 99 | +; CHECK-NEXT: ret |
| 100 | + %cmp.match = icmp ult i64 %y, %x |
| 101 | + %cmp.nomatch1 = icmp ult i64 %unrelated, %x |
| 102 | + %cmp.nomatch2 = icmp ugt i64 %y, %unrelated |
| 103 | + %or.nomatch = or i1 %cmp.nomatch1, %cmp.nomatch2 |
| 104 | + %and.cond = and i1 %or.nomatch, %cmp.match |
| 105 | + %sub.reuse = sub nuw i64 %y, %x |
| 106 | + %res = select i1 %and.cond, i64 0, i64 %sub.reuse |
| 107 | + ret i64 %res |
| 108 | +} |
| 109 | + |
| 110 | +; Negative test: There is no analogue of SUBS for floating point. |
| 111 | +define float @test_negative_float(float %unrelated, float %x, float %y) nounwind { |
| 112 | +; CHECK-LABEL: test_negative_float: |
| 113 | +; CHECK: // %bb.0: |
| 114 | +; CHECK-NEXT: fcmp s2, s0 |
| 115 | +; CHECK-NEXT: fsub s0, s2, s1 |
| 116 | +; CHECK-NEXT: movi d3, #0000000000000000 |
| 117 | +; CHECK-NEXT: fccmp s2, s1, #8, le |
| 118 | +; CHECK-NEXT: fcsel s0, s3, s0, mi |
| 119 | +; CHECK-NEXT: ret |
| 120 | + %cmp.nomatch1 = fcmp olt float %y, %x |
| 121 | + %cmp.nomatch2 = fcmp ogt float %y, %unrelated |
| 122 | + %or.cond = or i1 %cmp.nomatch1, %cmp.nomatch2 |
| 123 | + %sub.noreuse = fsub float %y, %x |
| 124 | + %res = select i1 %or.cond, float 0.0, float %sub.noreuse |
| 125 | + ret float %res |
| 126 | +} |
| 127 | + |
| 128 | +; Negative test: If both operands match a sub, do not reorder them. |
| 129 | +define i64 @test_prefer_right_negative(i64 %x, i64 %y, i64 %z) nounwind { |
| 130 | +; CHECK-LABEL: test_prefer_right_negative: |
| 131 | +; CHECK: // %bb.0: |
| 132 | +; CHECK-NEXT: cmp x2, x0 |
| 133 | +; CHECK-NEXT: ccmp x2, x1, #0, ls |
| 134 | +; CHECK-NEXT: csel x8, x0, x1, lo |
| 135 | +; CHECK-NEXT: sub x0, x2, x8 |
| 136 | +; CHECK-NEXT: ret |
| 137 | + %cmp.match1 = icmp ult i64 %z, %y |
| 138 | + %cmp.match2 = icmp ugt i64 %z, %x |
| 139 | + %or.cond = or i1 %cmp.match1, %cmp.match2 |
| 140 | + %sub.reuse1 = sub nuw i64 %z, %y |
| 141 | + %sub.reuse2 = sub nuw i64 %z, %x |
| 142 | + %res = select i1 %or.cond, i64 %sub.reuse2, i64 %sub.reuse1 |
| 143 | + ret i64 %res |
| 144 | +} |
0 commit comments