Skip to content

Commit ba447ec

Browse files
committed
[ARM] Prefer << 31 >> 31 over -(a & 1) for THUMB1 only
Materializing the 1 requires its own instruction for Thumb1
1 parent b698927 commit ba447ec

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

llvm/lib/Target/ARM/ARMInstrThumb.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,14 @@ def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
15711571
def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
15721572
(tCMPr tGPR:$Rn, tGPR:$Rm)>;
15731573

1574+
// -(n & 1) -> (n << 31) >> 31 to avoid materializing constants on Thumb1
1575+
def : T1Pat<(ineg (and tGPR:$Rn, (i32 1))),
1576+
(tASRri (tLSLri tGPR:$Rn, 31), 31)>,
1577+
Requires<[IsThumb, IsThumb1Only]>;
1578+
def : T1Pat<(sub (i32 0), (and tGPR:$Rn, (i32 1))),
1579+
(tASRri (tLSLri tGPR:$Rn, 31), 31)>,
1580+
Requires<[IsThumb, IsThumb1Only]>;
1581+
15741582
// Bswap 16 with load/store
15751583
def : T1Pat<(srl (bswap (extloadi16 t_addrmode_is2:$addr)), (i32 16)),
15761584
(tREV16 (tLDRHi t_addrmode_is2:$addr))>;

llvm/test/CodeGen/ARM/select_const.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,8 @@ define i32 @select_neg1_or_0(i1 %cond) {
276276
;
277277
; THUMB-LABEL: select_neg1_or_0:
278278
; THUMB: @ %bb.0:
279-
; THUMB-NEXT: movs r1, #1
280-
; THUMB-NEXT: ands r1, r0
281-
; THUMB-NEXT: rsbs r0, r1, #0
279+
; THUMB-NEXT: lsls r0, r0, #31
280+
; THUMB-NEXT: asrs r0, r0, #31
282281
; THUMB-NEXT: bx lr
283282
%sel = select i1 %cond, i32 -1, i32 0
284283
ret i32 %sel

0 commit comments

Comments
 (0)