xref: /llvm-project/llvm/test/Transforms/ConstantHoisting/ARM/gep-struct-index.ll (revision cee313d288a4faf0355d76fb6e0e927e211d08a5)
1; RUN: opt -consthoist -S < %s | FileCheck %s
2target triple = "thumbv6m-none-eabi"
3
4%T = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
5i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
6i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
7i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
8i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
9i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
10i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
11i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
12i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
13i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
14i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
15i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
16i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
17i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
18i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
19i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
20i32, i32, i32, i32, i32, i32 }
21
22; Indices for GEPs that index into a struct type should not be hoisted.
23define i32 @test1(%T* %P) nounwind {
24; CHECK-LABEL:  @test1
25; CHECK:        %const = bitcast i32 256 to i32
26; CHECK:        %addr1 = getelementptr %T, %T* %P, i32 %const, i32 256
27; CHECK:        %addr2 = getelementptr %T, %T* %P, i32 %const, i32 256
28; The first index into the pointer is hoisted, but the second one into the
29; struct isn't.
30  %addr1 = getelementptr %T, %T* %P, i32 256, i32 256
31  %tmp1 = load i32, i32* %addr1
32  %addr2 = getelementptr %T, %T* %P, i32 256, i32 256
33  %tmp2 = load i32, i32* %addr2
34  %tmp4 = add i32 %tmp1, %tmp2
35  ret i32 %tmp4
36}
37
38