1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00
llvm-mirror/test/CodeGen/Thumb/bic_imm.ll
Eli Friedman 251919f579 [ARM] Adjust AND immediates to make them cheaper to select.
LLVM normally prefers to minimize the number of bits set in an AND
immediate, but that doesn't always match the available ARM instructions.
In Thumb1 mode, prefer uxtb or uxth where possible; otherwise, prefer
a two-instruction sequence movs+ands or movs+bics.

Some potential improvements outlined in
ARMTargetLowering::targetShrinkDemandedConstant, but seems to work
pretty well already.

The ARMISelDAGToDAG fix ensures we don't generate an invalid UBFX
instruction due to a larger-than-expected mask. (It's orthogonal, in
some sense, but as far as I can tell it's either impossible or nearly
impossible to reproduce the bug without this change.)

According to my testing, this seems to consistently improve codesize by
a small amount by forming bic more often for ISD::AND with an immediate.

Differential Revision: https://reviews.llvm.org/D50030

llvm-svn: 339472
2018-08-10 21:21:53 +00:00

116 lines
3.0 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=thumbv7-linux-gnueabi -mcpu=cortex-m0 -verify-machineinstrs | FileCheck --check-prefix CHECK-T1 %s
; RUN: llc < %s -mtriple=thumbv7-linux-gnueabi -mcpu=cortex-m3 -verify-machineinstrs | FileCheck --check-prefix CHECK-T2 %s
define i32 @i(i32 %a) {
; CHECK-T1-LABEL: i:
; CHECK-T1: @ %bb.0: @ %entry
; CHECK-T1-NEXT: movs r1, #255
; CHECK-T1-NEXT: adds r1, #20
; CHECK-T1-NEXT: bics r0, r1
; CHECK-T1-NEXT: bx lr
;
; CHECK-T2-LABEL: i:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: movw r1, #275
; CHECK-T2-NEXT: bics r0, r1
; CHECK-T2-NEXT: bx lr
entry:
%and = and i32 %a, -276
ret i32 %and
}
define i32 @j(i32 %a) {
; CHECK-T1-LABEL: j:
; CHECK-T1: @ %bb.0: @ %entry
; CHECK-T1-NEXT: movs r1, #128
; CHECK-T1-NEXT: bics r0, r1
; CHECK-T1-NEXT: bx lr
;
; CHECK-T2-LABEL: j:
; CHECK-T2: @ %bb.0: @ %entry
; CHECK-T2-NEXT: bic r0, r0, #128
; CHECK-T2-NEXT: bx lr
entry:
%and = and i32 %a, -129
ret i32 %and
}
define void @truncated(i16 %a, i16* %p) {
; CHECK-T1-LABEL: truncated:
; CHECK-T1: @ %bb.0:
; CHECK-T1-NEXT: movs r2, #128
; CHECK-T1-NEXT: bics r0, r2
; CHECK-T1-NEXT: strh r0, [r1]
; CHECK-T1-NEXT: bx lr
;
; CHECK-T2-LABEL: truncated:
; CHECK-T2: @ %bb.0:
; CHECK-T2-NEXT: bic r0, r0, #128
; CHECK-T2-NEXT: strh r0, [r1]
; CHECK-T2-NEXT: bx lr
%and = and i16 %a, -129
store i16 %and, i16* %p
ret void
}
define void @truncated_neg2(i16 %a, i16* %p) {
; CHECK-T1-LABEL: truncated_neg2:
; CHECK-T1: @ %bb.0:
; CHECK-T1-NEXT: movs r2, #1
; CHECK-T1-NEXT: bics r0, r2
; CHECK-T1-NEXT: strh r0, [r1]
; CHECK-T1-NEXT: bx lr
;
; CHECK-T2-LABEL: truncated_neg2:
; CHECK-T2: @ %bb.0:
; CHECK-T2-NEXT: bic r0, r0, #1
; CHECK-T2-NEXT: strh r0, [r1]
; CHECK-T2-NEXT: bx lr
%and = and i16 %a, -2
store i16 %and, i16* %p
ret void
}
define void @truncated_neg256(i16 %a, i16* %p) {
; CHECK-T1-LABEL: truncated_neg256:
; CHECK-T1: @ %bb.0:
; CHECK-T1-NEXT: movs r2, #255
; CHECK-T1-NEXT: bics r0, r2
; CHECK-T1-NEXT: strh r0, [r1]
; CHECK-T1-NEXT: bx lr
;
; CHECK-T2-LABEL: truncated_neg256:
; CHECK-T2: @ %bb.0:
; CHECK-T2-NEXT: bic r0, r0, #255
; CHECK-T2-NEXT: strh r0, [r1]
; CHECK-T2-NEXT: bx lr
%and = and i16 %a, -256
store i16 %and, i16* %p
ret void
}
; FIXME: Thumb2 supports "bic r0, r0, #510"
define void @truncated_neg511(i16 %a, i16* %p) {
; CHECK-T1-LABEL: truncated_neg511:
; CHECK-T1: @ %bb.0:
; CHECK-T1-NEXT: ldr r2, .LCPI5_0
; CHECK-T1-NEXT: ands r2, r0
; CHECK-T1-NEXT: strh r2, [r1]
; CHECK-T1-NEXT: bx lr
; CHECK-T1-NEXT: .p2align 2
; CHECK-T1-NEXT: @ %bb.1:
; CHECK-T1-NEXT: .LCPI5_0:
; CHECK-T1-NEXT: .long 65025 @ 0xfe01
;
; CHECK-T2-LABEL: truncated_neg511:
; CHECK-T2: @ %bb.0:
; CHECK-T2-NEXT: movw r2, #65025
; CHECK-T2-NEXT: ands r0, r2
; CHECK-T2-NEXT: strh r0, [r1]
; CHECK-T2-NEXT: bx lr
%and = and i16 %a, -511
store i16 %and, i16* %p
ret void
}