|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals all --version 5 |
| 2 | +; RUN: opt -S -passes=early-cse < %s | FileCheck %s |
| 3 | + |
| 4 | +declare i8 @baz(i8, i8) |
| 5 | +declare i8 @baz_side_effects(i8, i8) |
| 6 | +declare i8 @buz(i8, i8) |
| 7 | + |
| 8 | +declare ptr @baz.ptr(i8, i8) |
| 9 | +declare i8 @buz.ptr(ptr, ptr) |
| 10 | +define i8 @same_parent_combine_diff_attrs(i8 %x, i8 %y) { |
| 11 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs( |
| 12 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 13 | +; CHECK-NEXT: [[C2:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR0:[0-9]+]] |
| 14 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 15 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C1]], i8 [[C2]]) |
| 16 | +; CHECK-NEXT: ret i8 [[R]] |
| 17 | +; |
| 18 | + %c1 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone |
| 19 | + %c0 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 20 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 21 | + ret i8 %r |
| 22 | + |
| 23 | +} |
| 24 | + |
| 25 | +define i8 @same_parent_combine_diff_attrs_needs_intersect(i8 %x, i8 %y) { |
| 26 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_needs_intersect( |
| 27 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 28 | +; CHECK-NEXT: [[C1:%.*]] = call nonnull ptr @baz.ptr(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 29 | +; CHECK-NEXT: [[C0:%.*]] = call ptr @baz.ptr(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 30 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz.ptr(ptr [[C0]], ptr [[C1]]) |
| 31 | +; CHECK-NEXT: ret i8 [[R]] |
| 32 | +; |
| 33 | + %c1 = call nonnull ptr @baz.ptr(i8 noundef %x, i8 noundef %y) readnone |
| 34 | + %c0 = call ptr @baz.ptr(i8 %x, i8 noundef %y) readnone |
| 35 | + %r = call i8 @buz.ptr(ptr %c0, ptr %c1) |
| 36 | + ret i8 %r |
| 37 | + |
| 38 | +} |
| 39 | + |
| 40 | +define i8 @same_parent_combine_diff_attrs_needs_intersect2(i8 %x, i8 %y) { |
| 41 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_needs_intersect2( |
| 42 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 43 | +; CHECK-NEXT: [[C1:%.*]] = call nonnull ptr @baz.ptr(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR1:[0-9]+]] |
| 44 | +; CHECK-NEXT: [[C0:%.*]] = call ptr @baz.ptr(i8 [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 45 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz.ptr(ptr [[C0]], ptr [[C1]]) |
| 46 | +; CHECK-NEXT: ret i8 [[R]] |
| 47 | +; |
| 48 | + %c1 = call nonnull ptr @baz.ptr(i8 noundef %x, i8 noundef %y) readonly |
| 49 | + %c0 = call ptr @baz.ptr(i8 %x, i8 noundef %y) readonly |
| 50 | + %r = call i8 @buz.ptr(ptr %c0, ptr %c1) |
| 51 | + ret i8 %r |
| 52 | + |
| 53 | +} |
| 54 | + |
| 55 | +define i8 @same_parent_combine_diff_attrs_really_needs_intersect(i8 %x, i8 %y) { |
| 56 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_really_needs_intersect( |
| 57 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 58 | +; CHECK-NEXT: [[C1:%.*]] = call nonnull ptr @baz.ptr(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 59 | +; CHECK-NEXT: [[C0:%.*]] = call ptr @baz.ptr(i8 [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 60 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz.ptr(ptr [[C0]], ptr noundef [[C1]]) |
| 61 | +; CHECK-NEXT: ret i8 [[R]] |
| 62 | +; |
| 63 | + %c1 = call nonnull ptr @baz.ptr(i8 noundef %x, i8 noundef %y) readonly |
| 64 | + %c0 = call ptr @baz.ptr(i8 %x, i8 noundef %y) readonly |
| 65 | + %r = call i8 @buz.ptr(ptr %c0, ptr noundef %c1) |
| 66 | + ret i8 %r |
| 67 | + |
| 68 | +} |
| 69 | + |
| 70 | +define i8 @same_parent_combine_diff_attrs_fail_side_effects(i8 %x, i8 %y) { |
| 71 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_fail_side_effects( |
| 72 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 73 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) |
| 74 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) |
| 75 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 76 | +; CHECK-NEXT: ret i8 [[R]] |
| 77 | +; |
| 78 | + %c1 = call i8 @baz(i8 noundef %x, i8 noundef %y) |
| 79 | + %c0 = call i8 @baz(i8 %x, i8 noundef %y) |
| 80 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 81 | + ret i8 %r |
| 82 | + |
| 83 | +} |
| 84 | + |
| 85 | +define i8 @same_parent_combine_diff_attrs_quasi_side_effects2(i8 %x, i8 %y) { |
| 86 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_quasi_side_effects2( |
| 87 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 88 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 89 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) |
| 90 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 91 | +; CHECK-NEXT: ret i8 [[R]] |
| 92 | +; |
| 93 | + %c1 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone |
| 94 | + %c0 = call i8 @baz(i8 %x, i8 noundef %y) |
| 95 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 96 | + ret i8 %r |
| 97 | + |
| 98 | +} |
| 99 | + |
| 100 | + |
| 101 | +define i8 @diff_parent_combine_diff_attrs(i1 %c, i8 %x, i8 %y) { |
| 102 | +; CHECK-LABEL: define i8 @diff_parent_combine_diff_attrs( |
| 103 | +; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 104 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 105 | +; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]] |
| 106 | +; CHECK: [[T]]: |
| 107 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 108 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 109 | +; CHECK-NEXT: ret i8 [[R]] |
| 110 | +; CHECK: [[F]]: |
| 111 | +; CHECK-NEXT: [[R2:%.*]] = add i8 [[C1]], 4 |
| 112 | +; CHECK-NEXT: ret i8 [[R2]] |
| 113 | +; |
| 114 | + %c1 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 115 | + br i1 %c, label %T, label %F |
| 116 | +T: |
| 117 | + %c0 = call i8 @baz(i8 noundef %x, i8 noundef %y) readonly |
| 118 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 119 | + ret i8 %r |
| 120 | +F: |
| 121 | + %r2 = add i8 %c1, 4 |
| 122 | + ret i8 %r2 |
| 123 | +} |
| 124 | + |
| 125 | +define i8 @diff_parent_combine_diff_attrs_preserves_return_attrs(i1 %c, i8 %x, i8 %y) { |
| 126 | +; CHECK-LABEL: define i8 @diff_parent_combine_diff_attrs_preserves_return_attrs( |
| 127 | +; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 128 | +; CHECK-NEXT: [[C1:%.*]] = call nonnull ptr @baz.ptr(i8 [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 129 | +; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]] |
| 130 | +; CHECK: [[T]]: |
| 131 | +; CHECK-NEXT: [[C0:%.*]] = call nonnull ptr @baz.ptr(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 132 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz.ptr(ptr [[C0]], ptr noundef [[C1]]) |
| 133 | +; CHECK-NEXT: ret i8 [[R]] |
| 134 | +; CHECK: [[F]]: |
| 135 | +; CHECK-NEXT: ret i8 9 |
| 136 | +; |
| 137 | + %c1 = call nonnull ptr @baz.ptr(i8 %x, i8 noundef %y) readonly |
| 138 | + br i1 %c, label %T, label %F |
| 139 | +T: |
| 140 | + %c0 = call nonnull ptr @baz.ptr(i8 noundef %x, i8 noundef %y) readonly |
| 141 | + %r = call i8 @buz.ptr(ptr %c0, ptr noundef %c1) |
| 142 | + ret i8 %r |
| 143 | +F: |
| 144 | + ret i8 9 |
| 145 | +} |
| 146 | + |
| 147 | +define i8 @same_parent_combine_diff_attrs_todo(i8 %x, i8 %y) { |
| 148 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_todo( |
| 149 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 150 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 151 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR2:[0-9]+]] |
| 152 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 153 | +; CHECK-NEXT: ret i8 [[R]] |
| 154 | +; |
| 155 | + %c1 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 156 | + %c0 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone alwaysinline |
| 157 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 158 | + ret i8 %r |
| 159 | + |
| 160 | +} |
| 161 | + |
| 162 | +define i8 @same_parent_combine_diff_attrs_fail(i8 %x, i8 %y) { |
| 163 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_fail( |
| 164 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 165 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 166 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR3:[0-9]+]] |
| 167 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 168 | +; CHECK-NEXT: ret i8 [[R]] |
| 169 | +; |
| 170 | + %c1 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 171 | + %c0 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone strictfp |
| 172 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 173 | + ret i8 %r |
| 174 | + |
| 175 | +} |
| 176 | + |
| 177 | +define i8 @diff_parent_combine_diff_attrs_todo(i1 %c, i8 %x, i8 %y) { |
| 178 | +; CHECK-LABEL: define i8 @diff_parent_combine_diff_attrs_todo( |
| 179 | +; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 180 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 181 | +; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]] |
| 182 | +; CHECK: [[T]]: |
| 183 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR4:[0-9]+]] |
| 184 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 185 | +; CHECK-NEXT: ret i8 [[R]] |
| 186 | +; CHECK: [[F]]: |
| 187 | +; CHECK-NEXT: [[R2:%.*]] = add i8 [[C1]], 4 |
| 188 | +; CHECK-NEXT: ret i8 [[R2]] |
| 189 | +; |
| 190 | + %c1 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 191 | + br i1 %c, label %T, label %F |
| 192 | +T: |
| 193 | + %c0 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone optnone noinline |
| 194 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 195 | + ret i8 %r |
| 196 | +F: |
| 197 | + %r2 = add i8 %c1, 4 |
| 198 | + ret i8 %r2 |
| 199 | +} |
| 200 | + |
| 201 | +define i8 @diff_parent_combine_diff_attrs_fail(i1 %c, i8 %x, i8 %y) { |
| 202 | +; CHECK-LABEL: define i8 @diff_parent_combine_diff_attrs_fail( |
| 203 | +; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 204 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 205 | +; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]] |
| 206 | +; CHECK: [[T]]: |
| 207 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR3]] |
| 208 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 209 | +; CHECK-NEXT: ret i8 [[R]] |
| 210 | +; CHECK: [[F]]: |
| 211 | +; CHECK-NEXT: [[R2:%.*]] = add i8 [[C1]], 4 |
| 212 | +; CHECK-NEXT: ret i8 [[R2]] |
| 213 | +; |
| 214 | + %c1 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 215 | + br i1 %c, label %T, label %F |
| 216 | +T: |
| 217 | + %c0 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone strictfp |
| 218 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 219 | + ret i8 %r |
| 220 | +F: |
| 221 | + %r2 = add i8 %c1, 4 |
| 222 | + ret i8 %r2 |
| 223 | +} |
| 224 | + |
| 225 | +;. |
| 226 | +; CHECK: attributes #[[ATTR0]] = { memory(none) } |
| 227 | +; CHECK: attributes #[[ATTR1]] = { memory(read) } |
| 228 | +; CHECK: attributes #[[ATTR2]] = { alwaysinline memory(none) } |
| 229 | +; CHECK: attributes #[[ATTR3]] = { strictfp memory(none) } |
| 230 | +; CHECK: attributes #[[ATTR4]] = { noinline optnone memory(none) } |
| 231 | +;. |
0 commit comments