1; RUN: opt < %s -scalarrepl -S | FileCheck %s 2 3target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" 4target triple = "i386-pc-linux-gnu" 5 6%nested = type { i32, [4 x i32] } 7 8; Check that a GEP with a non-zero first index does not prevent SROA as long 9; as the resulting offset corresponds to an element in the alloca. 10define i32 @test1() { 11; CHECK-LABEL: @test1( 12; CHECK-NOT: = i160 13; CHECK: ret i32 undef 14 %A = alloca %nested 15 %B = getelementptr %nested, %nested* %A, i32 0, i32 1, i32 0 16 %C = getelementptr i32, i32* %B, i32 2 17 %D = load i32, i32* %C 18 ret i32 %D 19} 20 21; But, if the offset is out of range, then it should not be transformed. 22define i32 @test2() { 23; CHECK-LABEL: @test2( 24; CHECK: i160 25 %A = alloca %nested 26 %B = getelementptr %nested, %nested* %A, i32 0, i32 1, i32 0 27 %C = getelementptr i32, i32* %B, i32 4 28 %D = load i32, i32* %C 29 ret i32 %D 30} 31 32; Try it with a bitcast and single GEP.... 33define i32 @test3() { 34; CHECK-LABEL: @test3( 35; CHECK-NOT: = i160 36; CHECK: ret i32 undef 37 %A = alloca %nested 38 %B = bitcast %nested* %A to i32* 39 %C = getelementptr i32, i32* %B, i32 2 40 %D = load i32, i32* %C 41 ret i32 %D 42} 43 44; ...and again make sure that out-of-range accesses are not transformed. 45define i32 @test4() { 46; CHECK-LABEL: @test4( 47; CHECK: i160 48 %A = alloca %nested 49 %B = bitcast %nested* %A to i32* 50 %C = getelementptr i32, i32* %B, i32 -1 51 %D = load i32, i32* %C 52 ret i32 %D 53} 54