1; RUN: opt < %s -S -basicaa -licm | FileCheck %s
2; RUN: opt -aa-pipeline=basic-aa -passes='lcssa,require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s -S | FileCheck %s
3; This fixes PR22460
4
5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6target triple = "x86_64-pc-windows-msvc"
7
8@in = internal unnamed_addr global i32* null, align 8
9@out = internal unnamed_addr global i32* null, align 8
10
11; CHECK-LABEL: @bar
12; CHECK: entry:
13; CHECK: load i64, i64* bitcast (i32** @in to i64*)
14; CHECK: do.body:
15; CHECK-NOT: load
16
17define i64 @bar(i32 %N) {
18entry:
19  br label %do.body
20
21do.body:                                          ; preds = %l2, %entry
22  %i.0 = phi i32 [ 0, %entry ], [ %inc, %l2 ]
23  %total = phi i64 [ 0, %entry ], [ %next, %l2 ]
24  %c = icmp eq i32 %N, 6
25  br i1 %c, label %l1, label %do.body.l2_crit_edge
26
27do.body.l2_crit_edge:                             ; preds = %do.body
28  %inval.pre = load i32*, i32** @in, align 8
29  br label %l2
30
31l1:                                               ; preds = %do.body
32  %v1 = load i64, i64* bitcast (i32** @in to i64*), align 8
33  store i64 %v1, i64* bitcast (i32** @out to i64*), align 8
34  %0 = inttoptr i64 %v1 to i32*
35  br label %l2
36
37l2:                                               ; preds = %do.body.l2_crit_edge, %l1
38  %inval = phi i32* [ %inval.pre, %do.body.l2_crit_edge ], [ %0, %l1 ]
39  %int = ptrtoint i32* %inval to i64
40  %next = add i64 %total, %int
41  %inc = add nsw i32 %i.0, 1
42  %cmp = icmp slt i32 %inc, %N
43  br i1 %cmp, label %do.body, label %do.end
44
45do.end:                                           ; preds = %l2
46  ret i64 %total
47}
48