xref: /llvm-project/polly/test/CodeGen/invariant_load_scalar_escape_alloca_sharing.ll (revision e1f056f692d869708c1898d9d65a69ac5584a0ed)
1; RUN: opt %loadNPMPolly -passes=polly-codegen -polly-invariant-load-hoisting=true -S < %s | FileCheck %s
2;
3; Verify the preloaded %tmp0 is stored and communicated in the same alloca.
4; In this case, we do not reload %ncol.load from the scalar stack slot, but
5; instead use directly the preloaded value stored in GlobalMap.
6;
7; CHECK-NOT: alloca
8; CHECK:     %tmp0.preload.s2a = alloca i32
9; CHECK-NOT: alloca
10;
11; CHECK:       %ncol.load = load i32, ptr @ncol
12; CHECK-NEXT:  store i32 %ncol.load, ptr %tmp0.preload.s2a
13;
14target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
15
16@ncol = external global i32, align 4
17
18define void @melt_data(ptr %data1, ptr %data2) {
19entry:
20  br label %entry.split
21
22entry.split:                                      ; preds = %entry
23  %tmp0 = load i32, ptr @ncol, align 4
24  %tobool.2 = icmp eq i32 %tmp0, 0
25  br i1 %tobool.2, label %while.end, label %while.body.lr.ph
26
27while.body.lr.ph:                                 ; preds = %entry.split
28  br label %while.body
29
30while.body:                                       ; preds = %while.body.lr.ph, %while.cond.backedge
31  %dec3.in = phi i32 [ %tmp0, %while.body.lr.ph ], [ %dec3, %while.cond.backedge ]
32  %dec3 = add nsw i32 %dec3.in, -1
33  %idxprom = sext i32 %dec3 to i64
34  %arrayidx = getelementptr inbounds i32, ptr %data1, i64 %idxprom
35  %tmp1 = load i32, ptr %arrayidx, align 4
36  %idxprom1 = sext i32 %dec3 to i64
37  %arrayidx2 = getelementptr inbounds i32, ptr %data2, i64 %idxprom1
38  %tmp2 = load i32, ptr %arrayidx2, align 4
39  %cmp = icmp sgt i32 %tmp1, %tmp2
40  br i1 %cmp, label %if.then, label %while.cond.backedge
41
42if.then:                                          ; preds = %while.body
43  %idxprom3 = sext i32 %dec3 to i64
44  %arrayidx4 = getelementptr inbounds i32, ptr %data2, i64 %idxprom3
45  %tmp3 = load i32, ptr %arrayidx4, align 4
46  %idxprom5 = sext i32 %dec3 to i64
47  %arrayidx6 = getelementptr inbounds i32, ptr %data1, i64 %idxprom5
48  store i32 %tmp3, ptr %arrayidx6, align 4
49  br label %while.cond.backedge
50
51while.cond.backedge:                              ; preds = %if.then, %while.body
52  %tobool = icmp eq i32 %dec3, 0
53  br i1 %tobool, label %while.cond.while.end_crit_edge, label %while.body
54
55while.cond.while.end_crit_edge:                   ; preds = %while.cond.backedge
56  br label %while.end
57
58while.end:                                        ; preds = %while.cond.while.end_crit_edge, %entry.split
59  ret void
60}
61