1; RUN: opt < %s -separate-const-offset-from-gep -slsr -gvn -S | FileCheck %s 2; RUN: llc < %s -march=nvptx64 -mcpu=sm_35 | FileCheck %s --check-prefix=PTX 3 4target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64" 5target triple = "nvptx64-unknown-unknown" 6 7; arr[i + 5] 8; arr[i * 2 + 5] 9; arr[i * 3 + 5] 10; arr[i * 4 + 5] 11; 12; => reassociate-geps 13; 14; *(&arr[i] + 5) 15; *(&arr[i * 2] + 5) 16; *(&arr[i * 3] + 5) 17; *(&arr[i * 4] + 5) 18; 19; => slsr 20; 21; p1 = &arr[i] 22; *(p1 + 5) 23; p2 = p1 + i 24; *(p2 + 5) 25; p3 = p2 + i 26; *(p3 + 5) 27; p4 = p3 + i 28; *(p4 + 5) 29define void @slsr_after_reassociate_geps(float* %arr, i32 %i) { 30; CHECK-LABEL: @slsr_after_reassociate_geps( 31; PTX-LABEL: .visible .func slsr_after_reassociate_geps( 32; PTX: ld.param.u64 [[arr:%rd[0-9]+]], [slsr_after_reassociate_geps_param_0]; 33; PTX: ld.param.u32 [[i:%r[0-9]+]], [slsr_after_reassociate_geps_param_1]; 34 %i2 = shl nsw i32 %i, 1 35 %i3 = mul nsw i32 %i, 3 36 %i4 = shl nsw i32 %i, 2 37 38 %j1 = add nsw i32 %i, 5 39 %p1 = getelementptr inbounds float, float* %arr, i32 %j1 40; CHECK: [[b1:%[0-9]+]] = getelementptr float, float* %arr, i64 [[bump:%[0-9]+]] 41; PTX: mul.wide.s32 [[i4:%rd[0-9]+]], [[i]], 4; 42; PTX: add.s64 [[base1:%rd[0-9]+]], [[arr]], [[i4]]; 43 %v1 = load float, float* %p1, align 4 44; PTX: ld.f32 {{%f[0-9]+}}, {{\[}}[[base1]]+20]; 45 call void @foo(float %v1) 46 47 %j2 = add nsw i32 %i2, 5 48 %p2 = getelementptr inbounds float, float* %arr, i32 %j2 49; CHECK: [[b2:%[0-9]+]] = getelementptr float, float* [[b1]], i64 [[bump]] 50; PTX: add.s64 [[base2:%rd[0-9]+]], [[base1]], [[i4]]; 51 %v2 = load float, float* %p2, align 4 52; PTX: ld.f32 {{%f[0-9]+}}, {{\[}}[[base2]]+20]; 53 call void @foo(float %v2) 54 55 %j3 = add nsw i32 %i3, 5 56 %p3 = getelementptr inbounds float, float* %arr, i32 %j3 57; CHECK: [[b3:%[0-9]+]] = getelementptr float, float* [[b2]], i64 [[bump]] 58; PTX: add.s64 [[base3:%rd[0-9]+]], [[base2]], [[i4]]; 59 %v3 = load float, float* %p3, align 4 60; PTX: ld.f32 {{%f[0-9]+}}, {{\[}}[[base3]]+20]; 61 call void @foo(float %v3) 62 63 %j4 = add nsw i32 %i4, 5 64 %p4 = getelementptr inbounds float, float* %arr, i32 %j4 65; CHECK: [[b4:%[0-9]+]] = getelementptr float, float* [[b3]], i64 [[bump]] 66; PTX: add.s64 [[base4:%rd[0-9]+]], [[base3]], [[i4]]; 67 %v4 = load float, float* %p4, align 4 68; PTX: ld.f32 {{%f[0-9]+}}, {{\[}}[[base4]]+20]; 69 call void @foo(float %v4) 70 71 ret void 72} 73 74declare void @foo(float) 75