OLD | NEW |
1 ; This tests some of the subtleties of Phi lowering. In particular, | 1 ; This tests some of the subtleties of Phi lowering. In particular, |
2 ; it tests that it does the right thing when it tries to enable | 2 ; it tests that it does the right thing when it tries to enable |
3 ; compare/branch fusing. | 3 ; compare/branch fusing. |
4 | 4 |
5 ; RUN: %p2i -i %s --args -O2 --verbose none --phi-edge-split=0 \ | 5 ; RUN: %p2i -i %s --assemble --disassemble --args -O2 --verbose none \ |
6 ; RUN: | llvm-mc -triple=i686-none-nacl -filetype=obj \ | 6 ; RUN: --phi-edge-split=0 \ |
7 ; RUN: | llvm-objdump -d -symbolize -x86-asm-syntax=intel - | FileCheck %s | 7 ; RUN: | FileCheck %s |
8 | 8 |
9 define internal i32 @testPhi1(i32 %arg) { | 9 define internal i32 @testPhi1(i32 %arg) { |
10 entry: | 10 entry: |
11 %cmp1 = icmp sgt i32 %arg, 0 | 11 %cmp1 = icmp sgt i32 %arg, 0 |
12 br i1 %cmp1, label %next, label %target | 12 br i1 %cmp1, label %next, label %target |
13 next: | 13 next: |
14 br label %target | 14 br label %target |
15 target: | 15 target: |
16 %merge = phi i1 [ %cmp1, %entry ], [ false, %next ] | 16 %merge = phi i1 [ %cmp1, %entry ], [ false, %next ] |
17 %result = zext i1 %merge to i32 | 17 %result = zext i1 %merge to i32 |
18 ret i32 %result | 18 ret i32 %result |
19 } | 19 } |
20 ; Test that compare/branch fusing does not happen, and Phi lowering is | 20 ; Test that compare/branch fusing does not happen, and Phi lowering is |
21 ; put in the right place. | 21 ; put in the right place. |
22 ; CHECK-LABEL: testPhi1 | 22 ; CHECK-LABEL: testPhi1 |
23 ; CHECK: cmp {{.*}}, 0 | 23 ; CHECK: cmp {{.*}},0x0 |
24 ; CHECK: mov {{.*}}, 1 | 24 ; CHECK: mov {{.*}},0x1 |
25 ; CHECK: jg | 25 ; CHECK: jg |
26 ; CHECK: mov {{.*}}, 0 | 26 ; CHECK: mov {{.*}},0x0 |
27 ; CHECK: mov [[PHI:.*]], | 27 ; CHECK: mov [[PHI:.*]], |
28 ; CHECK: cmp {{.*}}, 0 | 28 ; CHECK: cmp {{.*}},0x0 |
29 ; CHECK: je | 29 ; CHECK: je |
30 ; CHECK: mov [[PHI]], 0 | 30 ; CHECK: mov [[PHI]],0x0 |
31 ; CHECK: movzx {{.*}}, [[PHI]] | 31 ; CHECK: movzx {{.*}},[[PHI]] |
32 | 32 |
33 define internal i32 @testPhi2(i32 %arg) { | 33 define internal i32 @testPhi2(i32 %arg) { |
34 entry: | 34 entry: |
35 %cmp1 = icmp sgt i32 %arg, 0 | 35 %cmp1 = icmp sgt i32 %arg, 0 |
36 br i1 %cmp1, label %next, label %target | 36 br i1 %cmp1, label %next, label %target |
37 next: | 37 next: |
38 br label %target | 38 br label %target |
39 target: | 39 target: |
40 %merge = phi i32 [ 12345, %entry ], [ 54321, %next ] | 40 %merge = phi i32 [ 12345, %entry ], [ 54321, %next ] |
41 ret i32 %merge | 41 ret i32 %merge |
42 } | 42 } |
43 ; Test that compare/branch fusing and Phi lowering happens as expected. | 43 ; Test that compare/branch fusing and Phi lowering happens as expected. |
44 ; CHECK-LABEL: testPhi2 | 44 ; CHECK-LABEL: testPhi2 |
45 ; CHECK: mov {{.*}}, 12345 | 45 ; CHECK: mov {{.*}},0x3039 |
46 ; CHECK: cmp {{.*}}, 0 | 46 ; CHECK: cmp {{.*}},0x0 |
47 ; CHECK-NEXT: jle | 47 ; CHECK-NEXT: jle |
48 ; CHECK: mov [[PHI:.*]], 54321 | 48 ; CHECK: mov [[PHI:.*]],0xd431 |
49 ; CHECK: mov {{.*}}, [[PHI]] | 49 ; CHECK: mov {{.*}},[[PHI]] |
50 | 50 |
51 ; Test that address mode inference doesn't extend past | 51 ; Test that address mode inference doesn't extend past |
52 ; multi-definition, non-SSA Phi temporaries. | 52 ; multi-definition, non-SSA Phi temporaries. |
53 define internal i32 @testPhi3(i32 %arg) { | 53 define internal i32 @testPhi3(i32 %arg) { |
54 entry: | 54 entry: |
55 br label %body | 55 br label %body |
56 body: | 56 body: |
57 %merge = phi i32 [ %arg, %entry ], [ %elt, %body ] | 57 %merge = phi i32 [ %arg, %entry ], [ %elt, %body ] |
58 %interior = add i32 %merge, 1000 | 58 %interior = add i32 %merge, 1000 |
59 ; Trick to make a basic block local copy of interior for | 59 ; Trick to make a basic block local copy of interior for |
(...skipping 10 matching lines...) Expand all Loading... |
70 store i32 %arg, i32* %__6, align 1 | 70 store i32 %arg, i32* %__6, align 1 |
71 ret i32 %arg | 71 ret i32 %arg |
72 } | 72 } |
73 ; I can't figure out how to reliably test this for correctness, so I | 73 ; I can't figure out how to reliably test this for correctness, so I |
74 ; will just include patterns for the entire current O2 sequence. This | 74 ; will just include patterns for the entire current O2 sequence. This |
75 ; may need to be changed when meaningful optimizations are added. | 75 ; may need to be changed when meaningful optimizations are added. |
76 ; The key is to avoid the "bad" pattern like this: | 76 ; The key is to avoid the "bad" pattern like this: |
77 ; | 77 ; |
78 ; testPhi3: | 78 ; testPhi3: |
79 ; .LtestPhi3$entry: | 79 ; .LtestPhi3$entry: |
80 ; mov eax, dword ptr [esp+4] | 80 ; mov eax, DWORD PTR [esp+4] |
81 ; mov ecx, eax | 81 ; mov ecx, eax |
82 ; .LtestPhi3$body: | 82 ; .LtestPhi3$body: |
83 ; mov ecx, dword ptr [ecx+1000] | 83 ; mov ecx, DWORD PTR [ecx+1000] |
84 ; cmp ecx, 0 | 84 ; cmp ecx, 0 |
85 ; jne .LtestPhi3$body | 85 ; jne .LtestPhi3$body |
86 ; .LtestPhi3$exit: | 86 ; .LtestPhi3$exit: |
87 ; mov dword ptr [ecx+1000], eax | 87 ; mov DWORD PTR [ecx+1000], eax |
88 ; ret | 88 ; ret |
89 ; | 89 ; |
90 ; This is bad because the final store address is supposed to be the | 90 ; This is bad because the final store address is supposed to be the |
91 ; same as the load address in the loop, but it has clearly been | 91 ; same as the load address in the loop, but it has clearly been |
92 ; over-optimized into a null pointer dereference. | 92 ; over-optimized into a null pointer dereference. |
93 | 93 |
94 ; CHECK-LABEL: testPhi3 | 94 ; CHECK-LABEL: testPhi3 |
95 ; CHECK: push [[EBX:.*]] | 95 ; CHECK: push [[EBX:.*]] |
96 ; CHECK: mov {{.*}}, dword ptr [esp | 96 ; CHECK: mov {{.*}},DWORD PTR [esp |
97 ; CHECK: mov | 97 ; CHECK: mov |
98 ; CHECK: mov {{.*}}, dword ptr [[ADDR:.*1000]] | 98 ; CHECK: mov {{.*}},DWORD PTR [[ADDR:.*0x3e8]] |
99 ; CHECK: cmp {{.*}}, 0 | 99 ; CHECK: cmp {{.*}},0x0 |
100 ; CHECK: jne | 100 ; CHECK: jne |
101 ; CHECK: mov dword ptr [[ADDR]] | 101 ; CHECK: mov DWORD PTR [[ADDR]] |
102 ; CHECK: pop [[EBX]] | 102 ; CHECK: pop [[EBX]] |
OLD | NEW |