1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -passes=separate-const-offset-from-gep < %s | FileCheck %s 3 4target triple = "aarch64-linux-gnu" 5 6; Index is implicitly multiplied by vscale and so not really constant. 7define ptr @test1(ptr %base, i64 %idx) #0 { 8; CHECK-LABEL: @test1( 9; CHECK-NEXT: [[IDX_NEXT:%.*]] = add nuw nsw i64 [[IDX:%.*]], 1 10; CHECK-NEXT: [[GEP:%.*]] = getelementptr <vscale x 4 x float>, ptr [[BASE:%.*]], i64 [[IDX_NEXT]] 11; CHECK-NEXT: ret ptr [[GEP]] 12; 13 %idx.next = add nuw nsw i64 %idx, 1 14 %gep = getelementptr <vscale x 4 x float>, ptr %base, i64 %idx.next 15 ret ptr %gep 16} 17 18; Whilst the first index is not constant, the calculation of the second index 19; does contain a constant that can be extracted. 20define ptr @test2(ptr %base, i64 %idx) { 21; CHECK-LABEL: @test2( 22; CHECK-NEXT: [[TMP1:%.*]] = getelementptr <vscale x 4 x float>, ptr [[BASE:%.*]], i64 3, i64 [[IDX:%.*]] 23; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr [[TMP1]], i64 4 24; CHECK-NEXT: ret ptr [[GEP2]] 25; 26 %idx.next = add nuw nsw i64 %idx, 1 27 %gep = getelementptr <vscale x 4 x float>, ptr %base, i64 3, i64 %idx.next 28 ret ptr %gep 29} 30 31; Index is implicitly multiplied by vscale and so not really constant. 32define ptr @test3(ptr %base, i64 %idx) #0 { 33; CHECK-LABEL: @test3( 34; CHECK-NEXT: [[IDX_NEXT:%.*]] = add nuw nsw i64 [[IDX:%.*]], 1 35; CHECK-NEXT: [[GEP:%.*]] = getelementptr [8 x <vscale x 4 x float>], ptr [[BASE:%.*]], i64 [[IDX_NEXT]] 36; CHECK-NEXT: ret ptr [[GEP]] 37; 38 %idx.next = add nuw nsw i64 %idx, 1 39 %gep = getelementptr [8 x <vscale x 4 x float>], ptr %base, i64 %idx.next 40 ret ptr %gep 41} 42 43; Indices are implicitly multiplied by vscale and so not really constant. 44define ptr @test4(ptr %base, i64 %idx) { 45; CHECK-LABEL: @test4( 46; CHECK-NEXT: [[IDX_NEXT:%.*]] = add nuw nsw i64 [[IDX:%.*]], 1 47; CHECK-NEXT: [[GEP:%.*]] = getelementptr [8 x <vscale x 4 x float>], ptr [[BASE:%.*]], i64 3, i64 [[IDX_NEXT]] 48; CHECK-NEXT: ret ptr [[GEP]] 49; 50 %idx.next = add nuw nsw i64 %idx, 1 51 %gep = getelementptr [8 x <vscale x 4 x float>], ptr %base, i64 3, i64 %idx.next 52 ret ptr %gep 53} 54 55; Whilst the first two indices are not constant, the calculation of the third 56; index does contain a constant that can be extracted. 57define ptr @test5(ptr %base, i64 %idx) { 58; CHECK-LABEL: @test5( 59; CHECK-NEXT: [[TMP1:%.*]] = getelementptr [8 x <vscale x 4 x float>], ptr [[BASE:%.*]], i64 1, i64 3, i64 [[IDX:%.*]] 60; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr [[TMP1]], i64 4 61; CHECK-NEXT: ret ptr [[GEP2]] 62; 63 %idx.next = add nuw nsw i64 %idx, 1 64 %gep = getelementptr [8 x <vscale x 4 x float>], ptr %base, i64 1, i64 3, i64 %idx.next 65 ret ptr %gep 66} 67 68attributes #0 = { "target-features"="+sve" } 69