1 //! flags = ['-O2']
2 
3 // clang-format off
4 // clang -o codegen-optimized.wasm -target wasm32-unknown-wasip1 -g -O2 codegen-optimized.cpp
5 
6 // Make sure to adjust the break locations in lldb.rs when modifying this test.
7 #define BREAKPOINT
8 #define NOINLINE __attribute__((noinline))
9 
10 NOINLINE int NoInlineSideEffect() {
11   volatile int x = 1;
12   return x;
13 }
14 NOINLINE int NoInlineSideEffect_TwoArgs(int a, int b) {
15   volatile int x[] = {1, 2, 3};
16   return x[(a + b) >> 16];
17 }
18 
19 NOINLINE int VariableRanges_SingleVRegBrokenUp(int b) {
20   if (b < 0) {
21     __builtin_trap(); // This will split the live range of 'b'.
22   }
23   NoInlineSideEffect(); BREAKPOINT;
24   return b;
25 }
26 
27 NOINLINE int VariableRanges_SingleVRegRegReused(int b) {
28   int t = b & 420;
29   NoInlineSideEffect_TwoArgs(t, b); BREAKPOINT;
30   return 0;
31 }
32 
33 NOINLINE void InitializeTest(volatile int *x) {
34   *x = 42; // Have something to set a breakpoint on.
35 }
36 
37 int main(int argc, char *argv[]) {
38   volatile int x;
39   InitializeTest(&x);
40   VariableRanges_SingleVRegBrokenUp(x++);
41   VariableRanges_SingleVRegRegReused(x++);
42   return 0;
43 }
44