1 ; RUN: opt < %s -nary-reassociate -early-cse -S | FileCheck %s
3 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
4 target triple = "nvptx64-unknown-unknown"
6 declare void @foo(float*)
14 define void @reassociate_gep(float* %a, i64 %i, i64 %j) {
15 ; CHECK-LABEL: @reassociate_gep(
17 %2 = getelementptr float, float* %a, i64 %i
18 ; CHECK: [[t1:[^ ]+]] = getelementptr float, float* %a, i64 %i
19 call void @foo(float* %2)
20 ; CHECK: call void @foo(float* [[t1]])
21 %3 = getelementptr float, float* %a, i64 %1
22 ; CHECK: [[t2:[^ ]+]] = getelementptr float, float* [[t1]], i64 %j
23 call void @foo(float* %3)
24 ; CHECK: call void @foo(float* [[t2]])
29 ; foo(&a[sext(i +nsw j)]);
30 ; foo(&a[sext((i +nsw j) +nsw i)]);
36 ; t3 = t2 + sext(i); // sext(i) should be GVN'ed.
38 define void @reassociate_gep_nsw(float* %a, i32 %i, i32 %j) {
39 ; CHECK-LABEL: @reassociate_gep_nsw(
40 %idxprom.j = sext i32 %j to i64
41 %1 = getelementptr float, float* %a, i64 %idxprom.j
42 ; CHECK: [[t1:[^ ]+]] = getelementptr float, float* %a, i64 %idxprom.j
43 call void @foo(float* %1)
44 ; CHECK: call void @foo(float* [[t1]])
46 %2 = add nsw i32 %i, %j
47 %idxprom.2 = sext i32 %2 to i64
48 %3 = getelementptr float, float* %a, i64 %idxprom.2
49 ; CHECK: [[sexti:[^ ]+]] = sext i32 %i to i64
50 ; CHECK: [[t2:[^ ]+]] = getelementptr float, float* [[t1]], i64 [[sexti]]
51 call void @foo(float* %3)
52 ; CHECK: call void @foo(float* [[t2]])
54 %4 = add nsw i32 %2, %i
55 %idxprom.4 = sext i32 %4 to i64
56 %5 = getelementptr float, float* %a, i64 %idxprom.4
57 ; CHECK: [[t3:[^ ]+]] = getelementptr float, float* [[t2]], i64 [[sexti]]
58 call void @foo(float* %5)
59 ; CHECK: call void @foo(float* [[t3]])
64 ; Do not split the second GEP because sext(i + j) != sext(i) + sext(j).
65 define void @reassociate_gep_no_nsw(float* %a, i32 %i, i32 %j) {
66 ; CHECK-LABEL: @reassociate_gep_no_nsw(
68 %2 = getelementptr float, float* %a, i32 %j
69 ; CHECK: getelementptr float, float* %a, i32 %j
70 call void @foo(float* %2)
71 %3 = getelementptr float, float* %a, i32 %1
72 ; CHECK: getelementptr float, float* %a, i32 %1
73 call void @foo(float* %3)
77 define void @reassociate_gep_128(float* %a, i128 %i, i128 %j) {
78 ; CHECK-LABEL: @reassociate_gep_128(
80 %2 = getelementptr float, float* %a, i128 %i
81 ; CHECK: [[t1:[^ ]+]] = getelementptr float, float* %a, i128 %i
82 call void @foo(float* %2)
83 ; CHECK: call void @foo(float* [[t1]])
84 %3 = getelementptr float, float* %a, i128 %1
85 ; CHECK: [[truncj:[^ ]+]] = trunc i128 %j to i64
86 ; CHECK: [[t2:[^ ]+]] = getelementptr float, float* [[t1]], i64 [[truncj]]
87 call void @foo(float* %3)
88 ; CHECK: call void @foo(float* [[t2]])