xref: /llvm-project/llvm/test/Transforms/InstCombine/load-gep-overalign.ll (revision f5dbbf494ff0020978d7cdd052980e9ab9c05edb)
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
8declare void @report(i64 %index, i8 %val)
9
10define 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; NATURAL-LABEL: @test_vector_load_i8(
15; NATURAL-NEXT:    call void @report(i64 0, i8 1)
16; NATURAL-NEXT:    call void @report(i64 1, i8 35)
17; NATURAL-NEXT:    call void @report(i64 2, i8 69)
18; NATURAL-NEXT:    call void @report(i64 3, i8 103)
19; NATURAL-NEXT:    call void @report(i64 4, i8 -119)
20; NATURAL-NEXT:    call void @report(i64 5, i8 -85)
21; NATURAL-NEXT:    call void @report(i64 6, i8 -51)
22; NATURAL-NEXT:    call void @report(i64 7, i8 -17)
23; NATURAL-NEXT:    ret void
24;
25; OVERALIGNED-LABEL: @test_vector_load_i8(
26; OVERALIGNED-NEXT:    call void @report(i64 0, i8 1)
27; OVERALIGNED-NEXT:    call void @report(i64 1, i8 35)
28; OVERALIGNED-NEXT:    call void @report(i64 2, i8 69)
29; OVERALIGNED-NEXT:    call void @report(i64 3, i8 103)
30; OVERALIGNED-NEXT:    call void @report(i64 4, i8 -119)
31; OVERALIGNED-NEXT:    call void @report(i64 5, i8 -85)
32; OVERALIGNED-NEXT:    call void @report(i64 6, i8 -51)
33; OVERALIGNED-NEXT:    call void @report(i64 7, i8 -17)
34; OVERALIGNED-NEXT:    ret void
35;
36  %ptr0 = getelementptr i8, ptr @foo, i64 0
37  %res0 = load i8, ptr %ptr0, align 1
38  call void @report(i64 0, i8 %res0)
39
40  %ptr1 = getelementptr i8, ptr @foo, i64 1
41  %res1 = load i8, ptr %ptr1, align 1
42  call void @report(i64 1, i8 %res1)
43
44  %ptr2 = getelementptr i8, ptr @foo, i64 2
45  %res2 = load i8, ptr %ptr2, align 1
46  call void @report(i64 2, i8 %res2)
47
48  %ptr3 = getelementptr i8, ptr @foo, i64 3
49  %res3 = load i8, ptr %ptr3, align 1
50  call void @report(i64 3, i8 %res3)
51
52  %ptr4 = getelementptr i8, ptr @foo, i64 4
53  %res4 = load i8, ptr %ptr4, align 1
54  call void @report(i64 4, i8 %res4)
55
56  %ptr5 = getelementptr i8, ptr @foo, i64 5
57  %res5 = load i8, ptr %ptr5, align 1
58  call void @report(i64 5, i8 %res5)
59
60  %ptr6 = getelementptr i8, ptr @foo, i64 6
61  %res6 = load i8, ptr %ptr6, align 1
62  call void @report(i64 6, i8 %res6)
63
64  %ptr7 = getelementptr i8, ptr @foo, i64 7
65  %res7 = load i8, ptr %ptr7, align 1
66  call void @report(i64 7, i8 %res7)
67
68  ret void
69}
70