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