1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 @glob = internal global [10 x [10 x [10 x i32]]] zeroinitializer
6 define ptr @x12(i64 %x) {
7 ; CHECK-LABEL: define ptr @x12(
8 ; CHECK-SAME: i64 [[X:%.*]]) {
10 ; CHECK-NEXT: [[GEP_IDX:%.*]] = mul nsw i64 [[X]], 400
11 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr getelementptr inbounds nuw (i8, ptr @glob, i64 84), i64 [[GEP_IDX]]
12 ; CHECK-NEXT: ret ptr [[GEP]]
15 %gep = getelementptr inbounds [10 x [10 x [10 x i32]]], ptr getelementptr (i8, ptr @glob, i64 36), i64 0, i64 %x, i64 1, i64 2
19 define ptr @x1y(i64 %x, i64 %y) {
20 ; CHECK-LABEL: define ptr @x1y(
21 ; CHECK-SAME: i64 [[X:%.*]], i64 [[Y:%.*]]) {
23 ; CHECK-NEXT: [[GEP_IDX:%.*]] = mul nsw i64 [[X]], 400
24 ; CHECK-NEXT: [[GEP_IDX1:%.*]] = shl nsw i64 [[Y]], 2
25 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr i8, ptr getelementptr inbounds nuw (i8, ptr @glob, i64 116), i64 [[GEP_IDX]]
26 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[TMP0]], i64 [[GEP_IDX1]]
27 ; CHECK-NEXT: ret ptr [[GEP]]
30 %gep = getelementptr inbounds [10 x [10 x [10 x i32]]], ptr getelementptr (i8, ptr @glob, i64 36), i64 0, i64 %x, i64 2, i64 %y
34 define ptr @xzy(i64 %x, i64 %y, i64 %z) {
35 ; CHECK-LABEL: define ptr @xzy(
36 ; CHECK-SAME: i64 [[X:%.*]], i64 [[Y:%.*]], i64 [[Z:%.*]]) {
38 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [10 x [10 x [10 x i32]]], ptr getelementptr inbounds nuw (i8, ptr @glob, i64 40), i64 0, i64 [[X]], i64 [[Z]], i64 [[Y]]
39 ; CHECK-NEXT: ret ptr [[GEP]]
42 %gep = getelementptr inbounds [10 x [10 x [10 x i32]]], ptr getelementptr (i8, ptr @glob, i64 40), i64 0, i64 %x, i64 %z, i64 %y
46 define ptr @zerox(i64 %x) {
47 ; CHECK-LABEL: define ptr @zerox(
48 ; CHECK-SAME: i64 [[X:%.*]]) {
50 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [10 x i32], ptr getelementptr inbounds nuw (i8, ptr @glob, i64 32), i64 0, i64 [[X]]
51 ; CHECK-NEXT: ret ptr [[GEP]]
54 %gep = getelementptr inbounds [10 x i32], ptr getelementptr (i8, ptr @glob, i64 32), i64 0, i64 %x
58 define i32 @twoloads(i64 %x) {
59 ; CHECK-LABEL: define i32 @twoloads(
60 ; CHECK-SAME: i64 [[X:%.*]]) {
62 ; CHECK-NEXT: [[GEP1_IDX:%.*]] = mul nsw i64 [[X]], 400
63 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i8, ptr getelementptr inbounds nuw (i8, ptr @glob, i64 134), i64 [[GEP1_IDX]]
64 ; CHECK-NEXT: [[GEP2_IDX:%.*]] = mul nsw i64 [[X]], 400
65 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr getelementptr inbounds nuw (i8, ptr @glob, i64 132), i64 [[GEP2_IDX]]
66 ; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[GEP1]], align 4
67 ; CHECK-NEXT: [[B:%.*]] = load i32, ptr [[GEP2]], align 4
68 ; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]]
69 ; CHECK-NEXT: ret i32 [[C]]
72 %gep1 = getelementptr inbounds [10 x [10 x [10 x i32]]], ptr getelementptr (i8, ptr @glob, i64 50), i64 0, i64 %x, i64 2, i64 1
73 %gep2 = getelementptr inbounds [10 x [10 x [10 x i32]]], ptr getelementptr (i8, ptr @glob, i64 36), i64 0, i64 %x, i64 2, i64 4
74 %a = load i32, ptr %gep1
75 %b = load i32, ptr %gep2