1 ; RUN: opt < %s -basicaa -gvn -enable-load-pre -S | FileCheck %s
2 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
3 target triple = "aarch64--linux-gnu"
5 define double @foo(i32 %stat, i32 %i, double** %p) {
8 switch i32 %stat, label %sw.default [
14 sw.bb: ; preds = %entry, %entry
15 %idxprom = sext i32 %i to i64
16 %arrayidx = getelementptr inbounds double*, double** %p, i64 0
17 %0 = load double*, double** %arrayidx, align 8
18 %arrayidx1 = getelementptr inbounds double, double* %0, i64 %idxprom
19 %1 = load double, double* %arrayidx1, align 8
20 %sub = fsub double %1, 1.000000e+00
21 %cmp = fcmp olt double %sub, 0.000000e+00
22 br i1 %cmp, label %if.then, label %if.end
24 if.then: ; preds = %sw.bb
27 if.end: ; preds = %sw.bb
30 sw.bb2: ; preds = %if.end, %entry
31 %idxprom3 = sext i32 %i to i64
32 %arrayidx4 = getelementptr inbounds double*, double** %p, i64 0
33 %2 = load double*, double** %arrayidx4, align 8
34 %arrayidx5 = getelementptr inbounds double, double* %2, i64 %idxprom3
35 %3 = load double, double* %arrayidx5, align 8
37 ; CHECK-NEXT-NOT: sext
38 ; CHECK-NEXT: phi double [
40 %sub6 = fsub double 3.000000e+00, %3
43 sw.default: ; preds = %entry
46 return: ; preds = %sw.default, %sw.bb2, %if.then
47 %retval.0 = phi double [ 0.000000e+00, %sw.default ], [ %sub6, %sw.bb2 ], [ %sub, %if.then ]
51 ; The load causes the GEP's operands to be PREd earlier than normal. The
52 ; resulting sext ends up in pre.dest and in the GVN system before that BB is
53 ; actually processed. Make sure we can deal with the situation.
55 define void @test_shortcut_safe(i1 %tst, i32 %p1, i32* %a) {
56 ; CHECK-LABEL: define void @test_shortcut_safe
57 ; CHECK: [[SEXT1:%.*]] = sext i32 %p1 to i64
58 ; CHECK: [[PHI1:%.*]] = phi i64 [ [[SEXT1]], {{%.*}} ], [ [[PHI2:%.*]], {{%.*}} ]
59 ; CHECK: [[SEXT2:%.*]] = sext i32 %p1 to i64
60 ; CHECK: [[PHI2]] = phi i64 [ [[SEXT2]], {{.*}} ], [ [[PHI1]], {{%.*}} ]
61 ; CHECK: getelementptr inbounds i32, i32* %a, i64 [[PHI2]]
63 br i1 %tst, label %sext1, label %pre.dest
69 %idxprom = sext i32 %p1 to i64
73 %idxprom2 = sext i32 %p1 to i64
74 %arrayidx3 = getelementptr inbounds i32, i32* %a, i64 %idxprom2
75 %val = load i32, i32* %arrayidx3, align 4
76 tail call void (i32) @g(i32 %val)