|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | +; RUN: opt -passes=instcombine -S %s | FileCheck %s --check-prefix=NATURAL |
| 3 | +; RUN: opt --data-layout="i16:32" -passes=instcombine -S %s | FileCheck %s --check-prefix=OVERALIGNED |
| 4 | + |
| 5 | +; The data layouts are little endian, so @foo is 0x0123456789ABCDEF in memory. |
| 6 | +@foo = constant <4 x i16> <i16 u0x2301, i16 u0x6745, i16 u0xAB89, i16 u0xEFCD>, align 8 |
| 7 | + |
| 8 | +declare void @report(i64 %index, i8 %val) |
| 9 | + |
| 10 | +define void @test_vector_load_i8() { |
| 11 | +; Access and report each individual byte in @foo. |
| 12 | +; OVERALIGNED and NATURAL should have the same result, because the layout of vectors ignores |
| 13 | +; element type alignment, and thus the representation of @foo is the same in both cases. |
| 14 | +; |
| 15 | +; TODO: The OVERALIGNED result is incorrect. |
| 16 | +; First, for nonzero even indices, the valid load is replaced by poison. |
| 17 | +; Second, the remaining bytes at indices >= 2 are also incorrect, as apparently padding bytes |
| 18 | +; are assumed as they would appear in an array. In vectors, there is no padding. |
| 19 | +; |
| 20 | +; NATURAL-LABEL: @test_vector_load_i8( |
| 21 | +; NATURAL-NEXT: call void @report(i64 0, i8 1) |
| 22 | +; NATURAL-NEXT: call void @report(i64 1, i8 35) |
| 23 | +; NATURAL-NEXT: call void @report(i64 2, i8 69) |
| 24 | +; NATURAL-NEXT: call void @report(i64 3, i8 103) |
| 25 | +; NATURAL-NEXT: call void @report(i64 4, i8 -119) |
| 26 | +; NATURAL-NEXT: call void @report(i64 5, i8 -85) |
| 27 | +; NATURAL-NEXT: call void @report(i64 6, i8 -51) |
| 28 | +; NATURAL-NEXT: call void @report(i64 7, i8 -17) |
| 29 | +; NATURAL-NEXT: ret void |
| 30 | +; |
| 31 | +; OVERALIGNED-LABEL: @test_vector_load_i8( |
| 32 | +; OVERALIGNED-NEXT: call void @report(i64 0, i8 1) |
| 33 | +; OVERALIGNED-NEXT: call void @report(i64 1, i8 35) |
| 34 | +; OVERALIGNED-NEXT: call void @report(i64 2, i8 poison) |
| 35 | +; OVERALIGNED-NEXT: call void @report(i64 3, i8 0) |
| 36 | +; OVERALIGNED-NEXT: call void @report(i64 4, i8 poison) |
| 37 | +; OVERALIGNED-NEXT: call void @report(i64 5, i8 103) |
| 38 | +; OVERALIGNED-NEXT: call void @report(i64 6, i8 poison) |
| 39 | +; OVERALIGNED-NEXT: call void @report(i64 7, i8 0) |
| 40 | +; OVERALIGNED-NEXT: ret void |
| 41 | +; |
| 42 | + %ptr0 = getelementptr i8, ptr @foo, i64 0 |
| 43 | + %res0 = load i8, ptr %ptr0, align 1 |
| 44 | + call void @report(i64 0, i8 %res0) |
| 45 | + |
| 46 | + %ptr1 = getelementptr i8, ptr @foo, i64 1 |
| 47 | + %res1 = load i8, ptr %ptr1, align 1 |
| 48 | + call void @report(i64 1, i8 %res1) |
| 49 | + |
| 50 | + %ptr2 = getelementptr i8, ptr @foo, i64 2 |
| 51 | + %res2 = load i8, ptr %ptr2, align 1 |
| 52 | + call void @report(i64 2, i8 %res2) |
| 53 | + |
| 54 | + %ptr3 = getelementptr i8, ptr @foo, i64 3 |
| 55 | + %res3 = load i8, ptr %ptr3, align 1 |
| 56 | + call void @report(i64 3, i8 %res3) |
| 57 | + |
| 58 | + %ptr4 = getelementptr i8, ptr @foo, i64 4 |
| 59 | + %res4 = load i8, ptr %ptr4, align 1 |
| 60 | + call void @report(i64 4, i8 %res4) |
| 61 | + |
| 62 | + %ptr5 = getelementptr i8, ptr @foo, i64 5 |
| 63 | + %res5 = load i8, ptr %ptr5, align 1 |
| 64 | + call void @report(i64 5, i8 %res5) |
| 65 | + |
| 66 | + %ptr6 = getelementptr i8, ptr @foo, i64 6 |
| 67 | + %res6 = load i8, ptr %ptr6, align 1 |
| 68 | + call void @report(i64 6, i8 %res6) |
| 69 | + |
| 70 | + %ptr7 = getelementptr i8, ptr @foo, i64 7 |
| 71 | + %res7 = load i8, ptr %ptr7, align 1 |
| 72 | + call void @report(i64 7, i8 %res7) |
| 73 | + |
| 74 | + ret void |
| 75 | +} |
0 commit comments