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 define ptr @mul4(ptr %p, i64 %x) {
5 ; CHECK-LABEL: define ptr @mul4(
6 ; CHECK-SAME: ptr [[P:%.*]], i64 [[X:%.*]]) {
8 ; CHECK-NEXT: [[GEP_IDX:%.*]] = shl i64 [[X]], 4
9 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[GEP_IDX]]
10 ; CHECK-NEXT: ret ptr [[GEP]]
14 %gep = getelementptr inbounds i32, ptr %p, i64 %mul
18 define ptr @mul4_nuw(ptr %p, i64 %x) {
19 ; CHECK-LABEL: define ptr @mul4_nuw(
20 ; CHECK-SAME: ptr [[P:%.*]], i64 [[X:%.*]]) {
22 ; CHECK-NEXT: [[GEP_IDX:%.*]] = shl i64 [[X]], 4
23 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr nuw i8, ptr [[P]], i64 [[GEP_IDX]]
24 ; CHECK-NEXT: ret ptr [[GEP]]
28 %gep = getelementptr nuw i32, ptr %p, i64 %mul
32 define ptr @mul5(ptr %p, i64 %x) {
33 ; CHECK-LABEL: define ptr @mul5(
34 ; CHECK-SAME: ptr [[P:%.*]], i64 [[X:%.*]]) {
36 ; CHECK-NEXT: [[GEP_IDX:%.*]] = mul i64 [[X]], 20
37 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[GEP_IDX]]
38 ; CHECK-NEXT: ret ptr [[GEP]]
42 %gep = getelementptr inbounds i32, ptr %p, i64 %mul
46 define ptr @noinbounds(ptr %p, i64 %x) {
47 ; CHECK-LABEL: define ptr @noinbounds(
48 ; CHECK-SAME: ptr [[P:%.*]], i64 [[X:%.*]]) {
50 ; CHECK-NEXT: [[GEP_IDX:%.*]] = mul i64 [[X]], 20
51 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[P]], i64 [[GEP_IDX]]
52 ; CHECK-NEXT: ret ptr [[GEP]]
56 %gep = getelementptr i32, ptr %p, i64 %mul
60 define ptr @usemul(ptr %p, i64 %x) {
61 ; CHECK-LABEL: define ptr @usemul(
62 ; CHECK-SAME: ptr [[P:%.*]], i64 [[X:%.*]]) {
64 ; CHECK-NEXT: [[MUL:%.*]] = mul i64 [[X]], 5
65 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 [[MUL]]
66 ; CHECK-NEXT: call void @use(i64 [[MUL]])
67 ; CHECK-NEXT: ret ptr [[GEP]]
71 %gep = getelementptr inbounds i32, ptr %p, i64 %mul
72 call void @use(i64 %mul)
76 define void @multiple(ptr %p, i64 %x) {
77 ; CHECK-LABEL: define void @multiple(
78 ; CHECK-SAME: ptr [[P:%.*]], i64 [[X:%.*]]) {
80 ; CHECK-NEXT: [[MUL21:%.*]] = mul i64 [[X]], 20
81 ; CHECK-NEXT: [[GEP3:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[MUL21]]
82 ; CHECK-NEXT: [[MUL20:%.*]] = mul i64 [[X]], 20
83 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[MUL20]]
84 ; CHECK-NEXT: call void @use2(ptr [[GEP3]], ptr [[GEP2]])
85 ; CHECK-NEXT: ret void
89 %gep1 = getelementptr inbounds i32, ptr %p, i64 %mul5
90 %mul20 = mul i64 %x, 20
91 %gep2 = getelementptr inbounds i8, ptr %p, i64 %mul20
92 call void @use2(ptr %gep1, ptr %gep2)
96 define void @multiplestore(ptr %p, i64 %x) {
97 ; CHECK-LABEL: define void @multiplestore(
98 ; CHECK-SAME: ptr [[P:%.*]], i64 [[X:%.*]]) {
100 ; CHECK-NEXT: [[MUL20:%.*]] = mul i64 [[X]], 20
101 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[MUL20]]
102 ; CHECK-NEXT: [[MUL21:%.*]] = mul i64 [[X]], 20
103 ; CHECK-NEXT: [[GEP3:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[MUL21]]
104 ; CHECK-NEXT: store i32 0, ptr [[GEP2]], align 4
105 ; CHECK-NEXT: store i32 1, ptr [[GEP3]], align 4
106 ; CHECK-NEXT: ret void
109 %mul5 = mul i64 %x, 5
110 %gep1 = getelementptr inbounds i32, ptr %p, i64 %mul5
111 %mul20 = mul i64 %x, 20
112 %gep2 = getelementptr inbounds i8, ptr %p, i64 %mul20
113 store i32 0, ptr %gep1
114 store i32 1, ptr %gep2
118 declare void @use(i64)
119 declare void @use2(ptr, ptr)