Skip to content

Commit 31b25a6

Browse files
committed
!fixup add missing GISel implementation.
1 parent e60c54f commit 31b25a6

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,14 @@ void IRTranslator::emitSwitchCase(SwitchCG::CaseBlock &CB,
930930

931931
const LLT i1Ty = LLT::scalar(1);
932932
// Build the compare.
933-
if (!CB.CmpMHS) {
933+
if (CB.EmitAnd) {
934+
const LLT Ty = getLLTForType(*CB.CmpRHS->getType(), *DL);
935+
Register CondLHS = getOrCreateVReg(*CB.CmpLHS);
936+
Register C = getOrCreateVReg(*CB.CmpRHS);
937+
Register And = MIB.buildAnd(Ty, CondLHS, C).getReg(0);
938+
auto Zero = MIB.buildConstant(Ty, 0);
939+
Cond = MIB.buildICmp(CmpInst::ICMP_EQ, i1Ty, And, Zero).getReg(0);
940+
} else if (!CB.CmpMHS) {
934941
const auto *CI = dyn_cast<ConstantInt>(CB.CmpRHS);
935942
// For conditional branch lowering, we might try to do something silly like
936943
// emit an G_ICMP to compare an existing G_ICMP i1 result with true. If so,

llvm/test/CodeGen/AArch64/switch-cases-to-branch-and.ll

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,22 @@ define i32 @switch_with_matching_dests_0_and_pow2_3_cases(i8 %v) {
2929
;
3030
; GISEL-LABEL: switch_with_matching_dests_0_and_pow2_3_cases:
3131
; GISEL: ; %bb.0: ; %entry
32-
; GISEL-NEXT: mov w8, #100 ; =0x64
33-
; GISEL-NEXT: and w9, w0, #0xff
32+
; GISEL-NEXT: mov w8, w0
33+
; GISEL-NEXT: mov w9, #100 ; =0x64
34+
; GISEL-NEXT: mov w10, #223 ; =0xdf
3435
; GISEL-NEXT: mov w0, #20 ; =0x14
3536
; GISEL-NEXT: LBB0_1: ; %loop.header
3637
; GISEL-NEXT: ; =>This Inner Loop Header: Depth=1
37-
; GISEL-NEXT: tbnz wzr, #0, LBB0_4
38+
; GISEL-NEXT: tst w8, w10
39+
; GISEL-NEXT: b.eq LBB0_4
3840
; GISEL-NEXT: ; %bb.2: ; %loop.header
3941
; GISEL-NEXT: ; in Loop: Header=BB0_1 Depth=1
40-
; GISEL-NEXT: cmp w9, #124
42+
; GISEL-NEXT: and w11, w8, #0xff
43+
; GISEL-NEXT: cmp w11, #124
4144
; GISEL-NEXT: b.eq LBB0_5
4245
; GISEL-NEXT: ; %bb.3: ; %loop.latch
4346
; GISEL-NEXT: ; in Loop: Header=BB0_1 Depth=1
44-
; GISEL-NEXT: subs w8, w8, #1
47+
; GISEL-NEXT: subs w9, w9, #1
4548
; GISEL-NEXT: b.ne LBB0_1
4649
; GISEL-NEXT: LBB0_4: ; %common.ret
4750
; GISEL-NEXT: ret
@@ -102,13 +105,15 @@ define i32 @switch_with_matching_dests_0_and_pow2_3_cases_swapped(i8 %v) {
102105
; GISEL-LABEL: switch_with_matching_dests_0_and_pow2_3_cases_swapped:
103106
; GISEL: ; %bb.0: ; %entry
104107
; GISEL-NEXT: mov w8, #100 ; =0x64
105-
; GISEL-NEXT: and w9, w0, #0xff
108+
; GISEL-NEXT: mov w9, #223 ; =0xdf
106109
; GISEL-NEXT: LBB1_1: ; %loop.header
107110
; GISEL-NEXT: ; =>This Inner Loop Header: Depth=1
108-
; GISEL-NEXT: tbnz wzr, #0, LBB1_5
111+
; GISEL-NEXT: tst w0, w9
112+
; GISEL-NEXT: b.eq LBB1_5
109113
; GISEL-NEXT: ; %bb.2: ; %loop.header
110114
; GISEL-NEXT: ; in Loop: Header=BB1_1 Depth=1
111-
; GISEL-NEXT: cmp w9, #124
115+
; GISEL-NEXT: and w10, w0, #0xff
116+
; GISEL-NEXT: cmp w10, #124
112117
; GISEL-NEXT: b.eq LBB1_6
113118
; GISEL-NEXT: ; %bb.3: ; %loop.latch
114119
; GISEL-NEXT: ; in Loop: Header=BB1_1 Depth=1
@@ -184,26 +189,28 @@ define i32 @switch_with_matching_dests_0_and_pow2_3_cases_with_phi(i8 %v, i1 %c)
184189
;
185190
; GISEL-LABEL: switch_with_matching_dests_0_and_pow2_3_cases_with_phi:
186191
; GISEL: ; %bb.0: ; %entry
187-
; GISEL-NEXT: mov w8, w0
188-
; GISEL-NEXT: mov w0, wzr
192+
; GISEL-NEXT: mov w8, wzr
189193
; GISEL-NEXT: tbz w1, #0, LBB2_6
190194
; GISEL-NEXT: ; %bb.1: ; %loop.header.preheader
191-
; GISEL-NEXT: mov w9, #100 ; =0x64
192-
; GISEL-NEXT: and w8, w8, #0xff
195+
; GISEL-NEXT: mov w8, #100 ; =0x64
196+
; GISEL-NEXT: mov w9, #223 ; =0xdf
193197
; GISEL-NEXT: LBB2_2: ; %loop.header
194198
; GISEL-NEXT: ; =>This Inner Loop Header: Depth=1
195-
; GISEL-NEXT: tbnz wzr, #0, LBB2_7
199+
; GISEL-NEXT: tst w0, w9
200+
; GISEL-NEXT: b.eq LBB2_7
196201
; GISEL-NEXT: ; %bb.3: ; %loop.header
197202
; GISEL-NEXT: ; in Loop: Header=BB2_2 Depth=1
198-
; GISEL-NEXT: cmp w8, #124
203+
; GISEL-NEXT: and w10, w0, #0xff
204+
; GISEL-NEXT: cmp w10, #124
199205
; GISEL-NEXT: b.eq LBB2_8
200206
; GISEL-NEXT: ; %bb.4: ; %loop.latch
201207
; GISEL-NEXT: ; in Loop: Header=BB2_2 Depth=1
202-
; GISEL-NEXT: subs w9, w9, #1
208+
; GISEL-NEXT: subs w8, w8, #1
203209
; GISEL-NEXT: b.ne LBB2_2
204210
; GISEL-NEXT: ; %bb.5:
205-
; GISEL-NEXT: mov w0, #10 ; =0xa
211+
; GISEL-NEXT: mov w8, #10 ; =0xa
206212
; GISEL-NEXT: LBB2_6: ; %common.ret
213+
; GISEL-NEXT: mov w0, w8
207214
; GISEL-NEXT: ret
208215
; GISEL-NEXT: LBB2_7:
209216
; GISEL-NEXT: mov w0, #20 ; =0x14
@@ -359,10 +366,11 @@ define i32 @switch_in_loop_with_matching_dests_0_and_pow2_3_cases(ptr %start) {
359366
; GISEL-NEXT: add x8, x0, #1
360367
; GISEL-NEXT: LBB4_1: ; %loop
361368
; GISEL-NEXT: ; =>This Inner Loop Header: Depth=1
362-
; GISEL-NEXT: tbnz wzr, #0, LBB4_4
369+
; GISEL-NEXT: ldrb w9, [x8], #1
370+
; GISEL-NEXT: tst w9, #0xffffffdf
371+
; GISEL-NEXT: b.eq LBB4_4
363372
; GISEL-NEXT: ; %bb.2: ; %loop
364373
; GISEL-NEXT: ; in Loop: Header=BB4_1 Depth=1
365-
; GISEL-NEXT: ldrb w9, [x8], #1
366374
; GISEL-NEXT: cmp w9, #124
367375
; GISEL-NEXT: b.ne LBB4_1
368376
; GISEL-NEXT: ; %bb.3: ; %e2.loopexit
@@ -554,7 +562,7 @@ define void @test_successor_with_loop_phi(ptr %A, ptr %B) {
554562
; GISEL-NEXT: ldr w8, [x0]
555563
; GISEL-NEXT: str wzr, [x0]
556564
; GISEL-NEXT: mov x0, x1
557-
; GISEL-NEXT: cmn w8, #5
565+
; GISEL-NEXT: tst w8, #0xfffffffb
558566
; GISEL-NEXT: b.eq LBB7_1
559567
; GISEL-NEXT: ; %bb.2: ; %exit
560568
; GISEL-NEXT: ret
@@ -830,7 +838,9 @@ define void @merge_with_stores(ptr %A, i16 %v) {
830838
;
831839
; GISEL-LABEL: merge_with_stores:
832840
; GISEL: ; %bb.0: ; %entry
833-
; GISEL-NEXT: tbnz wzr, #0, LBB11_3
841+
; GISEL-NEXT: mov w8, #65533 ; =0xfffd
842+
; GISEL-NEXT: tst w1, w8
843+
; GISEL-NEXT: b.eq LBB11_3
834844
; GISEL-NEXT: ; %bb.1: ; %entry
835845
; GISEL-NEXT: mov w8, #-10 ; =0xfffffff6
836846
; GISEL-NEXT: add w8, w8, w1, uxth

0 commit comments

Comments
 (0)