|
| 1 | +;; Test reduction of: |
| 2 | +;; |
| 3 | +;; DST = shl i64 X, Y |
| 4 | +;; |
| 5 | +;; where Y is in the range [63-32] to: |
| 6 | +;; |
| 7 | +;; DST = [0, shl i32 X, (Y - 32)] |
| 8 | + |
| 9 | +; RUN: llc -mtriple=amdgcn-amd-amdhsa < %s | FileCheck %s |
| 10 | + |
| 11 | +; FIXME: This case should be reduced, but SelectionDAG::computeKnownBits() cannot |
| 12 | +; determine the minimum from metadata in this case. Match current results |
| 13 | +; for now. |
| 14 | +define i64 @shl_metadata(i64 noundef %arg0, ptr %arg1.ptr) { |
| 15 | + %shift.amt = load i64, ptr %arg1.ptr, !range !0 |
| 16 | + %shl = shl i64 %arg0, %shift.amt |
| 17 | + ret i64 %shl |
| 18 | + |
| 19 | +; CHECK: .globl shl_metadata |
| 20 | +; CHECK: v_lshl_b64 v[0:1], v[0:1], v2 |
| 21 | +} |
| 22 | + |
| 23 | +!0 = !{i64 32, i64 64} |
| 24 | + |
| 25 | +; This case is reduced because computeKnownBits() can calculates a minimum of 32 |
| 26 | +; based on the OR with 32. |
| 27 | +define i64 @shl_or32(i64 noundef %arg0, ptr %arg1.ptr) { |
| 28 | + %shift.amt = load i64, ptr %arg1.ptr |
| 29 | + %or = or i64 %shift.amt, 32 |
| 30 | + %shl = shl i64 %arg0, %or |
| 31 | + ret i64 %shl |
| 32 | + |
| 33 | +; CHECK: .globl shl_or32 |
| 34 | +; CHECK: v_or_b32_e32 v1, 32, v1 |
| 35 | +; CHECK: v_subrev_i32_e32 v1, vcc, 32, v1 |
| 36 | +; CHECK: v_lshlrev_b32_e32 v1, v1, v0 |
| 37 | +; CHECK: v_mov_b32_e32 v0, 0 |
| 38 | +} |
| 39 | + |
| 40 | +; This case must not be reduced because the known minimum, 16, is not in range. |
| 41 | +define i64 @shl_or16(i64 noundef %arg0, ptr %arg1.ptr) { |
| 42 | + %shift.amt = load i64, ptr %arg1.ptr |
| 43 | + %or = or i64 %shift.amt, 16 |
| 44 | + %shl = shl i64 %arg0, %or |
| 45 | + ret i64 %shl |
| 46 | + |
| 47 | +; CHECK: .globl shl_or16 |
| 48 | +; CHECK: v_or_b32_e32 v2, 16, v2 |
| 49 | +; CHECK: v_lshl_b64 v[0:1], v[0:1], v2 |
| 50 | +} |
| 51 | + |
| 52 | +; FIXME: This case should be reduced too, but computeKnownBits() cannot |
| 53 | +; determine the range. Match current results for now. |
| 54 | +define i64 @shl_maxmin(i64 noundef %arg0, i64 noundef %arg1) { |
| 55 | + %max = call i64 @llvm.umax.i64(i64 %arg1, i64 32) |
| 56 | + %min = call i64 @llvm.umin.i64(i64 %max, i64 63) |
| 57 | + %shl = shl i64 %arg0, %min |
| 58 | + ret i64 %shl |
| 59 | + |
| 60 | +; CHECK: .globl shl_maxmin |
| 61 | +; CHECK: v_cmp_lt_u64_e32 vcc, 32, v[2:3] |
| 62 | +; CHECK: v_cndmask_b32_e32 v3, 0, v3, vcc |
| 63 | +; CHECK: v_cndmask_b32_e32 v2, 32, v2, vcc |
| 64 | +; CHECK: v_cmp_gt_u64_e32 vcc, 63, v[2:3] |
| 65 | +; CHECK: v_cndmask_b32_e32 v2, 63, v2, vcc |
| 66 | +; CHECK: v_lshl_b64 v[0:1], v[0:1], v2 |
| 67 | +} |
0 commit comments