xref: /llvm-project/llvm/test/Transforms/Attributor/ArgumentPromotion/array.ll (revision a1db0e523d5a53f63b9907795eecd54d331a1b1c)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2; RUN: opt -attributor -enable-new-pm=0 -attributor-manifest-internal  -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM
3; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal  -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM
4; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM
5; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM
6;
7; FIXME: The GEP + BC + GEP solution we create is not great but correct.
8
9declare void @use(i32* nocapture readonly %arg)
10
11define void @caller() {
12; IS________OPM-LABEL: define {{[^@]+}}@caller() {
13; IS________OPM-NEXT:  entry:
14; IS________OPM-NEXT:    [[LEFT:%.*]] = alloca [3 x i32], align 4
15; IS________OPM-NEXT:    [[ARRAYDECAY:%.*]] = getelementptr inbounds [3 x i32], [3 x i32]* [[LEFT]], i64 0, i64 0
16; IS________OPM-NEXT:    call void @callee(i32* noalias nocapture noundef nonnull readonly align 4 dereferenceable(12) [[ARRAYDECAY]])
17; IS________OPM-NEXT:    ret void
18;
19; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@caller() {
20; IS__TUNIT_NPM-NEXT:  entry:
21; IS__TUNIT_NPM-NEXT:    [[LEFT:%.*]] = alloca [3 x i32], align 4
22; IS__TUNIT_NPM-NEXT:    [[ARRAYDECAY:%.*]] = getelementptr inbounds [3 x i32], [3 x i32]* [[LEFT]], i64 0, i64 0
23; IS__TUNIT_NPM-NEXT:    [[TMP0:%.*]] = bitcast i32* [[ARRAYDECAY]] to [3 x i32]*
24; IS__TUNIT_NPM-NEXT:    [[DOTCAST:%.*]] = bitcast [3 x i32]* [[TMP0]] to i32*
25; IS__TUNIT_NPM-NEXT:    [[TMP1:%.*]] = load i32, i32* [[DOTCAST]], align 4
26; IS__TUNIT_NPM-NEXT:    [[DOT0_1:%.*]] = getelementptr [3 x i32], [3 x i32]* [[TMP0]], i64 0, i64 1
27; IS__TUNIT_NPM-NEXT:    [[TMP2:%.*]] = load i32, i32* [[DOT0_1]], align 4
28; IS__TUNIT_NPM-NEXT:    [[DOT0_2:%.*]] = getelementptr [3 x i32], [3 x i32]* [[TMP0]], i64 0, i64 2
29; IS__TUNIT_NPM-NEXT:    [[TMP3:%.*]] = load i32, i32* [[DOT0_2]], align 4
30; IS__TUNIT_NPM-NEXT:    call void @callee(i32 [[TMP1]], i32 [[TMP2]], i32 [[TMP3]])
31; IS__TUNIT_NPM-NEXT:    ret void
32;
33; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@caller() {
34; IS__CGSCC_NPM-NEXT:  entry:
35; IS__CGSCC_NPM-NEXT:    call void @callee(i32 undef, i32 undef, i32 undef)
36; IS__CGSCC_NPM-NEXT:    ret void
37;
38entry:
39  %left = alloca [3 x i32], align 4
40  %arraydecay = getelementptr inbounds [3 x i32], [3 x i32]* %left, i64 0, i64 0
41  call void @callee(i32* %arraydecay)
42  ret void
43}
44
45define internal void @callee(i32* noalias %arg) {
46; IS________OPM-LABEL: define {{[^@]+}}@callee
47; IS________OPM-SAME: (i32* noalias nocapture noundef nonnull readonly align 4 dereferenceable(12) [[ARG:%.*]]) {
48; IS________OPM-NEXT:  entry:
49; IS________OPM-NEXT:    call void @use(i32* noalias nocapture noundef nonnull readonly align 4 dereferenceable(12) [[ARG]])
50; IS________OPM-NEXT:    ret void
51;
52; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@callee
53; IS__TUNIT_NPM-SAME: (i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]]) {
54; IS__TUNIT_NPM-NEXT:  entry:
55; IS__TUNIT_NPM-NEXT:    [[ARG_PRIV:%.*]] = alloca [3 x i32], align 4
56; IS__TUNIT_NPM-NEXT:    [[ARG_PRIV_CAST:%.*]] = bitcast [3 x i32]* [[ARG_PRIV]] to i32*
57; IS__TUNIT_NPM-NEXT:    store i32 [[TMP0]], i32* [[ARG_PRIV_CAST]], align 4
58; IS__TUNIT_NPM-NEXT:    [[ARG_PRIV_0_1:%.*]] = getelementptr [3 x i32], [3 x i32]* [[ARG_PRIV]], i64 0, i64 1
59; IS__TUNIT_NPM-NEXT:    store i32 [[TMP1]], i32* [[ARG_PRIV_0_1]], align 4
60; IS__TUNIT_NPM-NEXT:    [[ARG_PRIV_0_2:%.*]] = getelementptr [3 x i32], [3 x i32]* [[ARG_PRIV]], i64 0, i64 2
61; IS__TUNIT_NPM-NEXT:    store i32 [[TMP2]], i32* [[ARG_PRIV_0_2]], align 4
62; IS__TUNIT_NPM-NEXT:    [[TMP3:%.*]] = bitcast [3 x i32]* [[ARG_PRIV]] to i32*
63; IS__TUNIT_NPM-NEXT:    call void @use(i32* noalias nocapture noundef nonnull readonly align 4 dereferenceable(12) [[TMP3]])
64; IS__TUNIT_NPM-NEXT:    ret void
65;
66; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@callee
67; IS__CGSCC_NPM-SAME: (i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]]) {
68; IS__CGSCC_NPM-NEXT:  entry:
69; IS__CGSCC_NPM-NEXT:    [[ARG_PRIV:%.*]] = alloca [3 x i32], align 4
70; IS__CGSCC_NPM-NEXT:    [[ARG_PRIV_CAST:%.*]] = bitcast [3 x i32]* [[ARG_PRIV]] to i32*
71; IS__CGSCC_NPM-NEXT:    store i32 undef, i32* [[ARG_PRIV_CAST]], align 4
72; IS__CGSCC_NPM-NEXT:    [[ARG_PRIV_0_1:%.*]] = getelementptr [3 x i32], [3 x i32]* [[ARG_PRIV]], i64 0, i64 1
73; IS__CGSCC_NPM-NEXT:    store i32 undef, i32* [[ARG_PRIV_0_1]], align 4
74; IS__CGSCC_NPM-NEXT:    [[ARG_PRIV_0_2:%.*]] = getelementptr [3 x i32], [3 x i32]* [[ARG_PRIV]], i64 0, i64 2
75; IS__CGSCC_NPM-NEXT:    store i32 undef, i32* [[ARG_PRIV_0_2]], align 4
76; IS__CGSCC_NPM-NEXT:    [[TMP3:%.*]] = bitcast [3 x i32]* [[ARG_PRIV]] to i32*
77; IS__CGSCC_NPM-NEXT:    call void @use(i32* noalias nocapture noundef nonnull readonly align 4 dereferenceable(12) [[TMP3]])
78; IS__CGSCC_NPM-NEXT:    ret void
79;
80entry:
81  call void @use(i32* %arg)
82  ret void
83}
84