• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; This is a smoke test of random number generator.
2; The random number generators for different randomization passes should be
3; decoupled. The random number used in one randomization pass should not be
4; influenced by the existence of other randomization passes.
5
6; REQUIRES: allow_dump, target_X8632
7
8; Command for checking constant blinding (Need to turn off nop-insertion)
9; RUN: %p2i --target x8632 -i %s --filetype=obj --disassemble --args -O2 \
10; RUN:    -sz-seed=1 -randomize-pool-immediates=randomize \
11; RUN:    -randomize-pool-threshold=0x1 \
12; RUN:    -reorder-global-variables \
13; RUN:    -reorder-basic-blocks \
14; RUN:    -reorder-functions \
15; RUN:    -randomize-regalloc \
16; RUN:    -nop-insertion=0 \
17; RUN:    -reorder-pooled-constants \
18; RUN:    | FileCheck %s --check-prefix=BLINDINGO2
19
20; Command for checking global variable reordering
21; RUN: %p2i --target x8632 -i %s \
22; RUN:    --filetype=obj --disassemble --dis-flags=-rD \
23; RUN:    --args -O2 -sz-seed=1 \
24; RUN:    -randomize-pool-immediates=randomize \
25; RUN:    -randomize-pool-threshold=0x1 \
26; RUN:    -reorder-global-variables \
27; RUN:    -reorder-basic-blocks \
28; RUN:    -reorder-functions \
29; RUN:    -randomize-regalloc \
30; RUN:    -nop-insertion \
31; RUN:    -reorder-pooled-constants \
32; RUN:    | FileCheck %s --check-prefix=GLOBALVARS
33
34; Command for checking basic block reordering
35; RUN: %p2i --target x8632 -i %s --filetype=asm --args -O2 -sz-seed=1\
36; RUN:    -randomize-pool-immediates=randomize \
37; RUN:    -randomize-pool-threshold=0x1 \
38; RUN:    -reorder-global-variables \
39; RUN:    -reorder-basic-blocks \
40; RUN:    -reorder-functions \
41; RUN:    -randomize-regalloc \
42; RUN:    -nop-insertion \
43; RUN:    -reorder-pooled-constants \
44; RUN:    | FileCheck %s --check-prefix=BBREORDERING
45
46; Command for checking function reordering
47; RUN: %p2i --target x8632 -i %s --filetype=obj --disassemble --args -O2 \
48; RUN:    -sz-seed=1 -randomize-pool-immediates=randomize \
49; RUN:    -randomize-pool-threshold=0x1 \
50; RUN:    -reorder-global-variables \
51; RUN:    -reorder-basic-blocks \
52; RUN:    -reorder-functions \
53; RUN:    -randomize-regalloc \
54; RUN:    -nop-insertion \
55; RUN:    -reorder-pooled-constants \
56; RUN:    | FileCheck %s --check-prefix=FUNCREORDERING
57
58; Command for checking regalloc randomization
59; RUN: %p2i --target x8632 -i %s --filetype=obj --disassemble --args -O2 \
60; RUN:    -sz-seed=1 -randomize-pool-immediates=randomize \
61; RUN:    -randomize-pool-threshold=0x1 \
62; RUN:    -reorder-global-variables \
63; RUN:    -reorder-basic-blocks \
64; RUN:    -reorder-functions \
65; RUN:    -randomize-regalloc \
66; RUN:    -nop-insertion \
67; RUN:    -reorder-pooled-constants \
68; RUN:    -split-local-vars=0 \
69; RUN:    | FileCheck %s --check-prefix=REGALLOC
70
71; Command for checking nop insertion (Need to turn off randomize-regalloc)
72; RUN: %p2i --target x8632 -i %s --filetype=asm --args \
73; RUN:    -sz-seed=1 -randomize-pool-immediates=randomize \
74; RUN:    -reorder-global-variables \
75; RUN:    -reorder-basic-blocks \
76; RUN:    -reorder-functions \
77; RUN:    -randomize-regalloc=0 \
78; RUN:    -nop-insertion -nop-insertion-percentage=50\
79; RUN:    -reorder-pooled-constants \
80; RUN:    | FileCheck %s --check-prefix=NOPINSERTION
81
82; Command for checking pooled constants reordering
83; RUN: %p2i --target x8632 -i %s --filetype=obj --disassemble --dis-flags=-s \
84; RUN:    --args -O2 -sz-seed=1 \
85; RUN:    -randomize-pool-immediates=randomize \
86; RUN:    -randomize-pool-threshold=0x1 \
87; RUN:    -reorder-global-variables \
88; RUN:    -reorder-basic-blocks \
89; RUN:    -reorder-functions \
90; RUN:    -randomize-regalloc \
91; RUN:    -nop-insertion \
92; RUN:    -reorder-pooled-constants \
93; RUN:    | FileCheck %s --check-prefix=POOLEDCONSTANTS
94
95
96; Global variables copied from reorder-global-variables.ll
97@PrimitiveInit = internal global [4 x i8] c"\1B\00\00\00", align 4
98@PrimitiveInitConst = internal constant [4 x i8] c"\0D\00\00\00", align 4
99@ArrayInit = internal global [20 x i8] c"\0A\00\00\00\14\00\00\00\1E\00\00\00(\00\00\002\00\00\00", align 4
100@ArrayInitPartial = internal global [40 x i8] c"<\00\00\00F\00\00\00P\00\00\00Z\00\00\00d\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", align 4
101@PrimitiveInitStatic = internal global [4 x i8] zeroinitializer, align 4
102@PrimitiveUninit = internal global [4 x i8] zeroinitializer, align 4
103@ArrayUninit = internal global [20 x i8] zeroinitializer, align 4
104@ArrayUninitConstDouble = internal constant [200 x i8] zeroinitializer, align 8
105@ArrayUninitConstInt = internal constant [20 x i8] zeroinitializer, align 4
106
107
108define internal <4 x i32> @func1(<4 x i32> %a, <4 x i32> %b) {
109entry:
110  %res = mul <4 x i32> %a, %b
111  ret <4 x i32> %res
112
113; NOPINSERTION-LABEL: func1
114; NOPINSERTION: nop /* variant = 1 */
115; NOPINSERTION: subl $60, %esp
116; NOPINSERTION: nop /* variant = 3 */
117; NOPINSERTION: movups %xmm0, 32(%esp)
118; NOPINSERTION: movups %xmm1, 16(%esp)
119; NOPINSERTION: movups 32(%esp), %xmm0
120; NOPINSERTION: nop /* variant = 1 */
121; NOPINSERTION: pshufd $49, 32(%esp), %xmm1
122; NOPINSERTION: nop /* variant = 4 */
123; NOPINSERTION: pshufd $49, 16(%esp), %xmm2
124; NOPINSERTION: nop /* variant = 1 */
125; NOPINSERTION: pmuludq 16(%esp), %xmm0
126; NOPINSERTION: pmuludq %xmm2, %xmm1
127; NOPINSERTION: nop /* variant = 0 */
128; NOPINSERTION: shufps $136, %xmm1, %xmm0
129; NOPINSERTION: nop /* variant = 3 */
130; NOPINSERTION: pshufd $216, %xmm0, %xmm0
131; NOPINSERTION: nop /* variant = 1 */
132; NOPINSERTION: movups %xmm0, (%esp)
133; NOPINSERTION: movups (%esp), %xmm0
134; NOPINSERTION: addl $60, %esp
135; NOPINSERTION: ret
136}
137
138
139
140define internal float @func2(float* %arg) {
141entry:
142  %arg.int = ptrtoint float* %arg to i32
143  %addr.int = add i32 %arg.int, 200000
144  %addr.ptr = inttoptr i32 %addr.int to float*
145  %addr.load = load float, float* %addr.ptr, align 4
146  ret float %addr.load
147
148; BLINDINGO2-LABEL: func2
149; BLINDINGO2: lea [[REG:e[a-z]*]],{{[[]}}{{e[a-z]*}}+0x69ed4ee7{{[]]}}
150}
151
152define internal float @func3(i32 %arg, float %input) {
153entry:
154  switch i32 %arg, label %return [
155    i32 0, label %sw.bb
156    i32 1, label %sw.bb1
157    i32 2, label %sw.bb2
158    i32 3, label %sw.bb3
159    i32 4, label %sw.bb4
160  ]
161
162sw.bb:
163  %rbb = fadd float %input, 1.000000e+00
164  br label %return
165
166sw.bb1:
167  %rbb1 = fadd float %input, 2.000000e+00
168  br label %return
169
170sw.bb2:
171  %rbb2 = fadd float %input, 4.000000e+00
172  br label %return
173
174sw.bb3:
175  %rbb3 = fadd float %input, 5.000000e-01
176  br label %return
177
178sw.bb4:
179  %rbb4 = fadd float %input, 2.500000e-01
180  br label %return
181
182return:
183  %retval.0 = phi float [ %rbb, %sw.bb ], [ %rbb1, %sw.bb1 ], [ %rbb2, %sw.bb2 ], [ %rbb3, %sw.bb3 ], [ %rbb4, %sw.bb4], [ 0.000000e+00, %entry ]
184  ret float %retval.0
185}
186
187define internal <4 x i32> @func4(<4 x i32> %a, <4 x i32> %b) {
188entry:
189  %res = mul <4 x i32> %a, %b
190  ret <4 x i32> %res
191
192; REGALLOC-LABEL: func4
193; REGALLOC: movups  xmm3,xmm0
194; REGALLOC-NEXT: pshufd  xmm0,xmm0,0x31
195; REGALLOC-NEXT: pshufd  xmm4,xmm1,0x31
196; REGALLOC-NEXT: pmuludq xmm3,xmm1
197; REGALLOC-NEXT: pmuludq xmm0,xmm4
198; REGALLOC-NEXT: shufps  xmm3,xmm0,0x88
199; REGALLOC-NEXT: pshufd  xmm3,xmm3,0xd8
200; REGALLOC-NEXT: movups  xmm0,xmm3
201; REGALLOC-NEXT: ret
202}
203
204define internal void @func5(i32 %foo, i32 %bar) {
205entry:
206  %r1 = icmp eq i32 %foo, %bar
207  br i1 %r1, label %BB1, label %BB2
208BB1:
209  %r2 = icmp sgt i32 %foo, %bar
210  br i1 %r2, label %BB3, label %BB4
211BB2:
212  %r3 = icmp slt i32 %foo, %bar
213  br i1 %r3, label %BB3, label %BB4
214BB3:
215  ret void
216BB4:
217  ret void
218
219; BBREORDERING-LABEL: func5:
220; BBREORDERING: .Lfunc5$entry:
221; BBREORDERING: .Lfunc5$BB1:
222; BBREORDERING: .Lfunc5$BB2:
223; BBREORDERING: .Lfunc5$BB4:
224; BBREORDERING: .Lfunc5$BB3
225}
226
227define internal i32 @func6(i32 %arg) {
228entry:
229  %res = add i32 200000, %arg
230  ret i32 %res
231
232; BLINDINGO2-LABEL: func6
233; BLINDINGO2: mov [[REG:e[a-z]*]],0x77254ee7
234; BLINDINGO2-NEXT: lea [[REG]],{{[[]}}[[REG]]-0x772241a7{{[]]}}
235}
236
237; Check for function reordering
238; FUNCREORDERING-LABEL: func1
239; FUNCREORDERING-LABEL: func4
240; FUNCREORDERING-LABEL: func5
241; FUNCREORDERING-LABEL: func2
242; FUNCREORDERING-LABEL: func6
243; FUNCREORDERING-LABEL: func3
244
245; Check for global variable reordering
246; GLOBALVARS-LABEL: ArrayInit
247; GLOBALVARS-LABEL: PrimitiveInit
248; GLOBALVARS-LABEL: ArrayInitPartial
249; GLOBALVARS-LABEL: PrimitiveUninit
250; GLOBALVARS-LABEL: ArrayUninit
251; GLOBALVARS-LABEL: PrimitiveInitStatic
252; GLOBALVARS-LABEL: ArrayUninitConstDouble
253; GLOBALVARS-LABEL: ArrayUninitConstInt
254; GLOBALVARS-LABEL: PrimitiveInitConst
255
256; Check for pooled constant reordering
257; POOLEDCONSTANTS-LABEL: .rodata.cst4
258; POOLEDCONSTANTS: 0000803e 0000803f 0000003f 00008040
259; POOLEDCONSTANTS: 00000040
260