ARM: Better codegen for 64-bit compares.
authorPeter Collingbourne <peter@pcc.me.uk>
Mon, 21 Mar 2016 18:00:02 +0000 (18:00 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Mon, 21 Mar 2016 18:00:02 +0000 (18:00 +0000)
commit86b9fbe980dde2c93b59314d87434aebcdcd79a2
tree496616a456505d77af4aac2f8309dfad3e6dce2f
parent91b1d1ab6c1c027fc5f9bc5e22184d2e572b4026
ARM: Better codegen for 64-bit compares.

This introduces a custom lowering for ISD::SETCCE (introduced in r253572)
that allows us to emit a short code sequence for 64-bit compares.

Before:

push {r7, lr}
cmp r0, r2
mov.w r0, #0
mov.w r12, #0
it hs
movhs r0, #1
cmp r1, r3
it ge
movge.w r12, #1
it eq
moveq r12, r0
cmp.w r12, #0
bne .LBB1_2
@ BB#1:                                 @ %bb1
bl f
pop {r7, pc}
.LBB1_2:                                @ %bb2
bl g
pop {r7, pc}

After:

push {r7, lr}
subs r0, r0, r2
sbcs.w r0, r1, r3
bge .LBB1_2
@ BB#1:                                 @ %bb1
bl f
pop {r7, pc}
.LBB1_2:                                @ %bb2
bl g
pop {r7, pc}

Saves around 80KB in Chromium's libchrome.so.

Some notes on this patch:

- I don't much like the ARMISD::BRCOND and ARMISD::CMOV combines I
  introduced (nothing else needs them). However, they are necessary in
  order to avoid poor codegen, and they seem similar to existing combines
  in other backends (e.g. X86 combines (brcond (cmp (setcc Compare))) to
  (brcond Compare)).

- No support for Thumb-1. This is in principle possible, but we'd need
  to implement ARMISD::SUBE for Thumb-1.

Differential Revision: http://reviews.llvm.org/D15256

llvm-svn: 263962
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/lib/Target/ARM/ARMISelLowering.h
llvm/test/CodeGen/ARM/atomic-64bit.ll
llvm/test/CodeGen/ARM/atomic-ops-v8.ll
llvm/test/CodeGen/ARM/wide-compares.ll [new file with mode: 0644]