[X86] Teach convertToThreeAddress to handle SUB with immediate
authorCraig Topper <craig.topper@intel.com>
Mon, 15 Jul 2019 23:07:56 +0000 (23:07 +0000)
committerCraig Topper <craig.topper@intel.com>
Mon, 15 Jul 2019 23:07:56 +0000 (23:07 +0000)
commit51193871dafd99e79d7d19f62cffbdcdda238530
treee5690d055ecc0679b2841c93c3c87334017a8322
parentc48162db994ab6040c45d468ea95772b574ab3ef
[X86] Teach convertToThreeAddress to handle SUB with immediate

We mostly avoid sub with immediate but there are a couple cases that can create them. One is the add 128, %rax -> sub -128, %rax trick in isel. The other is when a SUB immediate gets created for a compare where both the flags and the subtract value is used. If we are unable to linearize the SelectionDAG to satisfy the flag user and the sub result user from the same instruction, we will clone the sub immediate for the two uses. The one that produces flags will eventually become a compare. The other will have its flag output dead, and could then be considered for LEA creation.

I added additional test cases to add.ll to show the the sub -128 trick gets converted to LEA and a case where we don't need to convert it.

This showed up in the current codegen for PR42571.

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

llvm-svn: 366151
llvm/lib/Target/X86/X86InstrArithmetic.td
llvm/lib/Target/X86/X86InstrInfo.cpp
llvm/test/CodeGen/X86/add.ll
llvm/test/CodeGen/X86/bmi-intrinsics-fast-isel-x86_64.ll
llvm/test/CodeGen/X86/bmi-intrinsics-fast-isel.ll
llvm/test/CodeGen/X86/cgp-usubo.ll
llvm/test/CodeGen/X86/tbm-intrinsics-fast-isel-x86_64.ll
llvm/test/CodeGen/X86/tbm-intrinsics-fast-isel.ll