1; RUN: opt -S -instcombine < %s | FileCheck %s
2target datalayout = "E-m:e-i64:64-n32:64"
3target triple = "powerpc64-unknown-linux-gnu"
4
5@f.a = private unnamed_addr constant [1 x i32] [i32 12], align 4
6@f.b = private unnamed_addr constant [1 x i32] [i32 55], align 4
7@f.c = linkonce unnamed_addr alias [1 x i32], [1 x i32]* @f.b
8
9define signext i32 @test1(i32 signext %x) #0 {
10entry:
11  %idxprom = sext i32 %x to i64
12  %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* @f.a, i64 0, i64 %idxprom
13  %0 = load i32, i32* %arrayidx, align 4
14  ret i32 %0
15
16; CHECK-LABEL: @test1
17; CHECK: ret i32 12
18}
19
20declare void @foo(i64* %p)
21define void @test2(i32 signext %x, i64 %v) #0 {
22entry:
23  %p = alloca i64
24  %idxprom = sext i32 %x to i64
25  %arrayidx = getelementptr inbounds i64, i64* %p, i64 %idxprom
26  store i64 %v, i64* %arrayidx
27  call void @foo(i64* %p)
28  ret void
29
30; CHECK-LABEL: @test2
31; CHECK: %p = alloca i64
32; CHECK: store i64 %v, i64* %p
33; CHECK: ret void
34}
35
36define signext i32 @test3(i32 signext %x, i1 %y) #0 {
37entry:
38  %idxprom = sext i32 %x to i64
39  %p = select i1 %y, [1 x i32]* @f.a, [1 x i32]* @f.b
40  %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* %p, i64 0, i64 %idxprom
41  %0 = load i32, i32* %arrayidx, align 4
42  ret i32 %0
43
44; CHECK-LABEL: @test3
45; CHECK: getelementptr inbounds [1 x i32], [1 x i32]* %p, i64 0, i64 0
46}
47
48define signext i32 @test4(i32 signext %x, i1 %y) #0 {
49entry:
50  %idxprom = sext i32 %x to i64
51  %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* @f.c, i64 0, i64 %idxprom
52  %0 = load i32, i32* %arrayidx, align 4
53  ret i32 %0
54
55; CHECK-LABEL: @test4
56; CHECK: getelementptr inbounds [1 x i32], [1 x i32]* @f.c, i64 0, i64 %idxprom
57}
58
59attributes #0 = { nounwind readnone }
60
61