llvm.org GIT mirror llvm / c621ae7
update this entry, now that Anton implemented shift/and lowering for switches. There is one really easy isel thing here with tst we are not getting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37400 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
1 changed file(s) with 66 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
6666
6767 //===---------------------------------------------------------------------===//
6868
69 We compiles the following using a jump table.
69 We compiles the following:
7070
7171 define i16 @func_entry_2E_ce(i32 %i) {
72 newFuncRoot:
73 br label %entry.ce
74
75 bb12.exitStub: ; preds = %entry.ce
76 ret i16 0
77
78 bb4.exitStub: ; preds = %entry.ce, %entry.ce, %entry.ce
79 ret i16 1
80
81 bb9.exitStub: ; preds = %entry.ce, %entry.ce, %entry.ce
82 ret i16 2
83
84 bb.exitStub: ; preds = %entry.ce
85 ret i16 3
86
87 entry.ce: ; preds = %newFuncRoot
8872 switch i32 %i, label %bb12.exitStub [
8973 i32 0, label %bb4.exitStub
9074 i32 1, label %bb9.exitStub
9478 i32 8, label %bb.exitStub
9579 i32 9, label %bb9.exitStub
9680 ]
81
82 bb12.exitStub:
83 ret i16 0
84
85 bb4.exitStub:
86 ret i16 1
87
88 bb9.exitStub:
89 ret i16 2
90
91 bb.exitStub:
92 ret i16 3
9793 }
94
95 into:
96
97 _func_entry_2E_ce:
98 mov r2, #1
99 lsl r2, r0
100 cmp r0, #9
101 bhi LBB1_4 @bb12.exitStub
102 LBB1_1: @newFuncRoot
103 mov r1, #13
104 tst r2, r1
105 bne LBB1_5 @bb4.exitStub
106 LBB1_2: @newFuncRoot
107 ldr r1, LCPI1_0
108 tst r2, r1
109 bne LBB1_6 @bb9.exitStub
110 LBB1_3: @newFuncRoot
111 mov r1, #1
112 lsl r1, r1, #8
113 tst r2, r1
114 bne LBB1_7 @bb.exitStub
115 LBB1_4: @bb12.exitStub
116 mov r0, #0
117 bx lr
118 LBB1_5: @bb4.exitStub
119 mov r0, #1
120 bx lr
121 LBB1_6: @bb9.exitStub
122 mov r0, #2
123 bx lr
124 LBB1_7: @bb.exitStub
125 mov r0, #3
126 bx lr
127 LBB1_8:
128 .align 2
129 LCPI1_0:
130 .long 642
131
98132
99133 gcc compiles to:
100134
123157 .align 2
124158 L11:
125159 .long 642
160
161
162 GCC is doing a couple of clever things here:
163 1. It is predicating one of the returns. This isn't a clear win though: in
164 cases where that return isn't taken, it is replacing one condbranch with
165 two 'ne' predicated instructions.
166 2. It is sinking the shift of "1 << i" into the tst, and using ands instead of
167 tst. This will probably require whole function isel.
168 3. GCC emits:
169 tst r1, #256
170 we emit:
171 mov r1, #1
172 lsl r1, r1, #8
173 tst r2, r1
174
126175
127176 //===---------------------------------------------------------------------===//
128177