|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 |
| 2 | +; RUN: opt < %s -passes=div-rem-pairs -S -mtriple=amdgcn-amd-amdhsa | FileCheck %s |
| 3 | + |
| 4 | +define i32 @basic(ptr %p, i32 %x, i32 %y) { |
| 5 | +; CHECK-LABEL: define i32 @basic( |
| 6 | +; CHECK-SAME: ptr [[P:%.*]], i32 [[X:%.*]], i32 [[Y:%.*]]) { |
| 7 | +; CHECK-NEXT: [[X_FROZEN:%.*]] = freeze i32 [[X]] |
| 8 | +; CHECK-NEXT: [[Y_FROZEN:%.*]] = freeze i32 [[Y]] |
| 9 | +; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[X_FROZEN]], [[Y_FROZEN]] |
| 10 | +; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[DIV]], [[Y_FROZEN]] |
| 11 | +; CHECK-NEXT: [[REM_DECOMPOSED:%.*]] = sub i32 [[X_FROZEN]], [[TMP1]] |
| 12 | +; CHECK-NEXT: store i32 [[DIV]], ptr [[P]], align 4 |
| 13 | +; CHECK-NEXT: ret i32 [[REM_DECOMPOSED]] |
| 14 | +; |
| 15 | + %div = udiv i32 %x, %y |
| 16 | + %rem = urem i32 %x, %y |
| 17 | + store i32 %div, ptr %p, align 4 |
| 18 | + ret i32 %rem |
| 19 | +} |
| 20 | + |
| 21 | +define i32 @no_freezes(ptr %p, i32 noundef %x, i32 noundef %y) { |
| 22 | +; CHECK-LABEL: define i32 @no_freezes( |
| 23 | +; CHECK-SAME: ptr [[P:%.*]], i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) { |
| 24 | +; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[X]], [[Y]] |
| 25 | +; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[DIV]], [[Y]] |
| 26 | +; CHECK-NEXT: [[REM_DECOMPOSED:%.*]] = sub i32 [[X]], [[TMP1]] |
| 27 | +; CHECK-NEXT: store i32 [[DIV]], ptr [[P]], align 4 |
| 28 | +; CHECK-NEXT: ret i32 [[REM_DECOMPOSED]] |
| 29 | +; |
| 30 | + %div = udiv i32 %x, %y |
| 31 | + %rem = urem i32 %x, %y |
| 32 | + store i32 %div, ptr %p, align 4 |
| 33 | + ret i32 %rem |
| 34 | +} |
| 35 | + |
| 36 | +; FIXME: There should be no need to `freeze` x2 and y2 since they have defined |
| 37 | +; but potentially poison values. |
| 38 | +define i32 @poison_does_not_freeze(ptr %p, i32 noundef %x, i32 noundef %y) { |
| 39 | +; CHECK-LABEL: define i32 @poison_does_not_freeze( |
| 40 | +; CHECK-SAME: ptr [[P:%.*]], i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) { |
| 41 | +; CHECK-NEXT: [[X2:%.*]] = shl nuw nsw i32 [[X]], 5 |
| 42 | +; CHECK-NEXT: [[Y2:%.*]] = add nuw nsw i32 [[Y]], 1 |
| 43 | +; CHECK-NEXT: [[X2_FROZEN:%.*]] = freeze i32 [[X2]] |
| 44 | +; CHECK-NEXT: [[Y2_FROZEN:%.*]] = freeze i32 [[Y2]] |
| 45 | +; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[X2_FROZEN]], [[Y2_FROZEN]] |
| 46 | +; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[DIV]], [[Y2_FROZEN]] |
| 47 | +; CHECK-NEXT: [[REM_DECOMPOSED:%.*]] = sub i32 [[X2_FROZEN]], [[TMP1]] |
| 48 | +; CHECK-NEXT: store i32 [[DIV]], ptr [[P]], align 4 |
| 49 | +; CHECK-NEXT: ret i32 [[REM_DECOMPOSED]] |
| 50 | +; |
| 51 | + %x2 = shl nuw nsw i32 %x, 5 |
| 52 | + %y2 = add nuw nsw i32 %y, 1 |
| 53 | + %div = udiv i32 %x2, %y2 |
| 54 | + %rem = urem i32 %x2, %y2 |
| 55 | + store i32 %div, ptr %p, align 4 |
| 56 | + ret i32 %rem |
| 57 | +} |
| 58 | + |
| 59 | +define i32 @poison_does_not_freeze_signed(ptr %p, i32 noundef %x, i32 noundef %y) { |
| 60 | +; CHECK-LABEL: define i32 @poison_does_not_freeze_signed( |
| 61 | +; CHECK-SAME: ptr [[P:%.*]], i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) { |
| 62 | +; CHECK-NEXT: [[X2:%.*]] = shl nuw nsw i32 [[X]], 5 |
| 63 | +; CHECK-NEXT: [[Y2:%.*]] = add nuw nsw i32 [[Y]], 1 |
| 64 | +; CHECK-NEXT: [[X2_FROZEN:%.*]] = freeze i32 [[X2]] |
| 65 | +; CHECK-NEXT: [[Y2_FROZEN:%.*]] = freeze i32 [[Y2]] |
| 66 | +; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[X2_FROZEN]], [[Y2_FROZEN]] |
| 67 | +; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[DIV]], [[Y2_FROZEN]] |
| 68 | +; CHECK-NEXT: [[REM_DECOMPOSED:%.*]] = sub i32 [[X2_FROZEN]], [[TMP1]] |
| 69 | +; CHECK-NEXT: store i32 [[DIV]], ptr [[P]], align 4 |
| 70 | +; CHECK-NEXT: ret i32 [[REM_DECOMPOSED]] |
| 71 | +; |
| 72 | + %x2 = shl nuw nsw i32 %x, 5 |
| 73 | + %y2 = add nuw nsw i32 %y, 1 |
| 74 | + %div = sdiv i32 %x2, %y2 |
| 75 | + %rem = srem i32 %x2, %y2 |
| 76 | + store i32 %div, ptr %p, align 4 |
| 77 | + ret i32 %rem |
| 78 | +} |
| 79 | + |
| 80 | +define <4 x i8> @poison_does_not_freeze_vector(ptr %p, <4 x i8> noundef %x, <4 x i8> noundef %y) { |
| 81 | +; CHECK-LABEL: define <4 x i8> @poison_does_not_freeze_vector( |
| 82 | +; CHECK-SAME: ptr [[P:%.*]], <4 x i8> noundef [[X:%.*]], <4 x i8> noundef [[Y:%.*]]) { |
| 83 | +; CHECK-NEXT: [[X2:%.*]] = shl nuw nsw <4 x i8> [[X]], <i8 5, i8 5, i8 5, i8 5> |
| 84 | +; CHECK-NEXT: [[Y2:%.*]] = add nuw nsw <4 x i8> [[Y]], <i8 1, i8 1, i8 1, i8 1> |
| 85 | +; CHECK-NEXT: [[X2_FROZEN:%.*]] = freeze <4 x i8> [[X2]] |
| 86 | +; CHECK-NEXT: [[Y2_FROZEN:%.*]] = freeze <4 x i8> [[Y2]] |
| 87 | +; CHECK-NEXT: [[DIV:%.*]] = udiv <4 x i8> [[X2_FROZEN]], [[Y2_FROZEN]] |
| 88 | +; CHECK-NEXT: [[TMP1:%.*]] = mul <4 x i8> [[DIV]], [[Y2_FROZEN]] |
| 89 | +; CHECK-NEXT: [[REM_DECOMPOSED:%.*]] = sub <4 x i8> [[X2_FROZEN]], [[TMP1]] |
| 90 | +; CHECK-NEXT: store <4 x i8> [[DIV]], ptr [[P]], align 4 |
| 91 | +; CHECK-NEXT: ret <4 x i8> [[REM_DECOMPOSED]] |
| 92 | +; |
| 93 | + %x2 = shl nuw nsw <4 x i8> %x, <i8 5, i8 5, i8 5, i8 5> |
| 94 | + %y2 = add nuw nsw <4 x i8> %y, <i8 1, i8 1, i8 1, i8 1> |
| 95 | + %div = udiv <4 x i8> %x2, %y2 |
| 96 | + %rem = urem <4 x i8> %x2, %y2 |
| 97 | + store <4 x i8> %div, ptr %p, align 4 |
| 98 | + ret <4 x i8> %rem |
| 99 | +} |
| 100 | + |
| 101 | +define i32 @explicit_poison_does_not_freeze(ptr %p, i32 noundef %y) { |
| 102 | +; CHECK-LABEL: define i32 @explicit_poison_does_not_freeze( |
| 103 | +; CHECK-SAME: ptr [[P:%.*]], i32 noundef [[Y:%.*]]) { |
| 104 | +; CHECK-NEXT: [[X:%.*]] = add i32 poison, 1 |
| 105 | +; CHECK-NEXT: [[Y2:%.*]] = add nuw nsw i32 [[Y]], 1 |
| 106 | +; CHECK-NEXT: [[X_FROZEN:%.*]] = freeze i32 [[X]] |
| 107 | +; CHECK-NEXT: [[Y2_FROZEN:%.*]] = freeze i32 [[Y2]] |
| 108 | +; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[X_FROZEN]], [[Y2_FROZEN]] |
| 109 | +; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[DIV]], [[Y2_FROZEN]] |
| 110 | +; CHECK-NEXT: [[REM_DECOMPOSED:%.*]] = sub i32 [[X_FROZEN]], [[TMP1]] |
| 111 | +; CHECK-NEXT: store i32 [[DIV]], ptr [[P]], align 4 |
| 112 | +; CHECK-NEXT: ret i32 [[REM_DECOMPOSED]] |
| 113 | +; |
| 114 | + %x = add i32 poison, 1 |
| 115 | + %y2 = add nuw nsw i32 %y, 1 |
| 116 | + %div = udiv i32 %x, %y2 |
| 117 | + %rem = urem i32 %x, %y2 |
| 118 | + store i32 %div, ptr %p, align 4 |
| 119 | + ret i32 %rem |
| 120 | +} |
| 121 | + |
| 122 | +define i32 @explicit_poison_does_not_freeze_signed(ptr %p, i32 noundef %y) { |
| 123 | +; CHECK-LABEL: define i32 @explicit_poison_does_not_freeze_signed( |
| 124 | +; CHECK-SAME: ptr [[P:%.*]], i32 noundef [[Y:%.*]]) { |
| 125 | +; CHECK-NEXT: [[X:%.*]] = add i32 poison, 1 |
| 126 | +; CHECK-NEXT: [[Y2:%.*]] = add nuw nsw i32 [[Y]], 1 |
| 127 | +; CHECK-NEXT: [[X_FROZEN:%.*]] = freeze i32 [[X]] |
| 128 | +; CHECK-NEXT: [[Y2_FROZEN:%.*]] = freeze i32 [[Y2]] |
| 129 | +; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[X_FROZEN]], [[Y2_FROZEN]] |
| 130 | +; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[DIV]], [[Y2_FROZEN]] |
| 131 | +; CHECK-NEXT: [[REM_DECOMPOSED:%.*]] = sub i32 [[X_FROZEN]], [[TMP1]] |
| 132 | +; CHECK-NEXT: store i32 [[DIV]], ptr [[P]], align 4 |
| 133 | +; CHECK-NEXT: ret i32 [[REM_DECOMPOSED]] |
| 134 | +; |
| 135 | + %x = add i32 poison, 1 |
| 136 | + %y2 = add nuw nsw i32 %y, 1 |
| 137 | + %div = sdiv i32 %x, %y2 |
| 138 | + %rem = srem i32 %x, %y2 |
| 139 | + store i32 %div, ptr %p, align 4 |
| 140 | + ret i32 %rem |
| 141 | +} |
0 commit comments