xref: /llvm-project/llvm/test/Transforms/ArgumentPromotion/2008-07-02-array-indexing.ll (revision bcbc6151640f53e9d78392c66de9760c664d8b1d)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
2; RUN: opt < %s -passes=argpromotion -S | FileCheck %s
3; PR2498
4
5; This test tries to convince CHECK about promoting the load from %A + 2,
6; because there is a load of %A in the entry block
7define internal i32 @callee(i1 %C, ptr %A) {
8; CHECK-LABEL: define {{[^@]+}}@callee
9; CHECK-SAME: (i1 [[C:%.*]], ptr [[A:%.*]]) {
10; CHECK-NEXT:  entry:
11; CHECK-NEXT:    [[A_0:%.*]] = load i32, ptr [[A]], align 4
12; CHECK-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
13; CHECK:       T:
14; CHECK-NEXT:    ret i32 [[A_0]]
15; CHECK:       F:
16; CHECK-NEXT:    [[A_2:%.*]] = getelementptr i32, ptr [[A]], i32 2
17; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[A_2]], align 4
18; CHECK-NEXT:    ret i32 [[R]]
19;
20entry:
21  ; Unconditonally load the element at %A
22  %A.0 = load i32, ptr %A
23  br i1 %C, label %T, label %F
24
25T:
26  ret i32 %A.0
27
28F:
29  ; Load the element at offset two from %A. This should not be promoted!
30  %A.2 = getelementptr i32, ptr %A, i32 2
31  %R = load i32, ptr %A.2
32  ret i32 %R
33}
34
35define i32 @foo() {
36; CHECK-LABEL: define {{[^@]+}}@foo() {
37; CHECK-NEXT:    [[X:%.*]] = call i32 @callee(i1 false, ptr null)
38; CHECK-NEXT:    ret i32 [[X]]
39;
40  %X = call i32 @callee(i1 false, ptr null)             ; <i32> [#uses=1]
41  ret i32 %X
42}
43
44