1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt %s -scalarizer -scalarize-load-store -S | FileCheck %s 3; RUN: opt %s -passes='function(scalarizer)' -scalarize-load-store -S | FileCheck %s 4 5; This verifies that the order of extract element instructions is 6; deterministic. In the past we could end up with different results depending 7; on the compiler used (due to argument evaluation order being undefined in 8; C++). The order of the extracts is not really important for correctness of 9; the result, but when debugging and creating test cases it is helpful if we 10; get the same out put regardless of which compiler we use when building the 11; compiler. 12 13define <2 x i32> @test1(i1 %b, <2 x i32> %i, <2 x i32> %j) { 14; CHECK-LABEL: @test1( 15; CHECK-NEXT: [[I_I0:%.*]] = extractelement <2 x i32> [[I:%.*]], i32 0 16; CHECK-NEXT: [[J_I0:%.*]] = extractelement <2 x i32> [[J:%.*]], i32 0 17; CHECK-NEXT: [[RES_I0:%.*]] = select i1 [[B:%.*]], i32 [[I_I0]], i32 [[J_I0]] 18; CHECK-NEXT: [[I_I1:%.*]] = extractelement <2 x i32> [[I]], i32 1 19; CHECK-NEXT: [[J_I1:%.*]] = extractelement <2 x i32> [[J]], i32 1 20; CHECK-NEXT: [[RES_I1:%.*]] = select i1 [[B]], i32 [[I_I1]], i32 [[J_I1]] 21; CHECK-NEXT: [[RES_UPTO0:%.*]] = insertelement <2 x i32> undef, i32 [[RES_I0]], i32 0 22; CHECK-NEXT: [[RES:%.*]] = insertelement <2 x i32> [[RES_UPTO0]], i32 [[RES_I1]], i32 1 23; CHECK-NEXT: ret <2 x i32> [[RES]] 24; 25 %res = select i1 %b, <2 x i32> %i, <2 x i32> %j 26 ret <2 x i32> %res 27} 28 29define <2 x i32> @test2(<2 x i1> %b, <2 x i32> %i, <2 x i32> %j) { 30; CHECK-LABEL: @test2( 31; CHECK-NEXT: [[B_I0:%.*]] = extractelement <2 x i1> [[B:%.*]], i32 0 32; CHECK-NEXT: [[I_I0:%.*]] = extractelement <2 x i32> [[I:%.*]], i32 0 33; CHECK-NEXT: [[J_I0:%.*]] = extractelement <2 x i32> [[J:%.*]], i32 0 34; CHECK-NEXT: [[RES_I0:%.*]] = select i1 [[B_I0]], i32 [[I_I0]], i32 [[J_I0]] 35; CHECK-NEXT: [[B_I1:%.*]] = extractelement <2 x i1> [[B]], i32 1 36; CHECK-NEXT: [[I_I1:%.*]] = extractelement <2 x i32> [[I]], i32 1 37; CHECK-NEXT: [[J_I1:%.*]] = extractelement <2 x i32> [[J]], i32 1 38; CHECK-NEXT: [[RES_I1:%.*]] = select i1 [[B_I1]], i32 [[I_I1]], i32 [[J_I1]] 39; CHECK-NEXT: [[RES_UPTO0:%.*]] = insertelement <2 x i32> undef, i32 [[RES_I0]], i32 0 40; CHECK-NEXT: [[RES:%.*]] = insertelement <2 x i32> [[RES_UPTO0]], i32 [[RES_I1]], i32 1 41; CHECK-NEXT: ret <2 x i32> [[RES]] 42; 43 %res = select <2 x i1> %b, <2 x i32> %i, <2 x i32> %j 44 ret <2 x i32> %res 45} 46 47define <2 x i32> @test3(<2 x i32> %i, <2 x i32> %j) { 48; CHECK-LABEL: @test3( 49; CHECK-NEXT: [[I_I0:%.*]] = extractelement <2 x i32> [[I:%.*]], i32 0 50; CHECK-NEXT: [[J_I0:%.*]] = extractelement <2 x i32> [[J:%.*]], i32 0 51; CHECK-NEXT: [[RES_I0:%.*]] = add nuw nsw i32 [[I_I0]], [[J_I0]] 52; CHECK-NEXT: [[I_I1:%.*]] = extractelement <2 x i32> [[I]], i32 1 53; CHECK-NEXT: [[J_I1:%.*]] = extractelement <2 x i32> [[J]], i32 1 54; CHECK-NEXT: [[RES_I1:%.*]] = add nuw nsw i32 [[I_I1]], [[J_I1]] 55; CHECK-NEXT: [[RES_UPTO0:%.*]] = insertelement <2 x i32> undef, i32 [[RES_I0]], i32 0 56; CHECK-NEXT: [[RES:%.*]] = insertelement <2 x i32> [[RES_UPTO0]], i32 [[RES_I1]], i32 1 57; CHECK-NEXT: ret <2 x i32> [[RES]] 58; 59 %res = add nuw nsw <2 x i32> %i, %j 60 ret <2 x i32> %res 61} 62 63define void @test4(<2 x i32>* %ptr, <2 x i32> %val) { 64; CHECK-LABEL: @test4( 65; CHECK-NEXT: [[VAL_I0:%.*]] = extractelement <2 x i32> [[VAL:%.*]], i32 0 66; CHECK-NEXT: [[PTR_I0:%.*]] = bitcast <2 x i32>* [[PTR:%.*]] to i32* 67; CHECK-NEXT: store i32 [[VAL_I0]], i32* [[PTR_I0]], align 8 68; CHECK-NEXT: [[VAL_I1:%.*]] = extractelement <2 x i32> [[VAL]], i32 1 69; CHECK-NEXT: [[PTR_I1:%.*]] = getelementptr i32, i32* [[PTR_I0]], i32 1 70; CHECK-NEXT: store i32 [[VAL_I1]], i32* [[PTR_I1]], align 4 71; CHECK-NEXT: ret void 72; 73 store <2 x i32> %val, <2 x i32> *%ptr 74 ret void 75} 76 77