1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
3 target datalayout = "E-m:e-i64:64-n32:64"
4 target triple = "powerpc64-unknown-linux-gnu"
6 @f.a = private unnamed_addr constant [1 x i32] [i32 12], align 4
7 @f.b = private unnamed_addr constant [1 x i32] [i32 55], align 4
8 @f.c = linkonce unnamed_addr alias [1 x i32], [1 x i32]* @f.b
10 define signext i32 @test1(i32 signext %x) #0 {
11 ; CHECK-LABEL: @test1(
12 ; CHECK-NEXT: ret i32 12
14 %idxprom = sext i32 %x to i64
15 %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* @f.a, i64 0, i64 %idxprom
16 %r = load i32, i32* %arrayidx, align 4
20 declare void @foo(i64* %p)
21 define void @test2(i32 signext %x, i64 %v) #0 {
22 ; CHECK-LABEL: @test2(
23 ; CHECK-NEXT: [[P:%.*]] = alloca i64, align 8
24 ; CHECK-NEXT: store i64 [[V:%.*]], i64* [[P]], align 8
25 ; CHECK-NEXT: call void @foo(i64* nonnull [[P]]) #1
26 ; CHECK-NEXT: ret void
29 %idxprom = sext i32 %x to i64
30 %arrayidx = getelementptr inbounds i64, i64* %p, i64 %idxprom
31 store i64 %v, i64* %arrayidx
32 call void @foo(i64* %p)
36 define signext i32 @test3(i32 signext %x, i1 %y) #0 {
37 ; CHECK-LABEL: @test3(
38 ; CHECK-NEXT: [[R:%.*]] = select i1 [[Y:%.*]], i32 12, i32 55
39 ; CHECK-NEXT: ret i32 [[R]]
41 %idxprom = sext i32 %x to i64
42 %p = select i1 %y, [1 x i32]* @f.a, [1 x i32]* @f.b
43 %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* %p, i64 0, i64 %idxprom
44 %r = load i32, i32* %arrayidx, align 4
48 define signext i32 @test4(i32 signext %x, i1 %y) #0 {
49 ; CHECK-LABEL: @test4(
50 ; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[X:%.*]] to i64
51 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* @f.c, i64 0, i64 [[IDXPROM]]
52 ; CHECK-NEXT: [[R:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
53 ; CHECK-NEXT: ret i32 [[R]]
55 %idxprom = sext i32 %x to i64
56 %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* @f.c, i64 0, i64 %idxprom
57 %r = load i32, i32* %arrayidx, align 4
61 attributes #0 = { nounwind readnone }