llvm-project/llvm/test
Sanjay Patel 962ee178fa [DAGCombiner] eliminate setcc bool math when input is low-bit of some value
This patch has the same motivating example as D48466:
define void @foo(i64 %x, i32 %c.0282.in, i32 %d.0280, i32* %ptr0, i32* %ptr1) {
    %c.0282 = and i32 %c.0282.in, 268435455
    %a16 = lshr i64 32508, %x
    %a17 = and i64 %a16, 1
    %tobool = icmp eq i64 %a17, 0
    %. = select i1 %tobool, i32 1, i32 2
    %.286 = select i1 %tobool, i32 27, i32 26
    %shr97 = lshr i32 %c.0282, %.
    %shl98 = shl i32 %c.0282.in, %.286
    %or99 = or i32 %shr97, %shl98
    %shr100 = lshr i32 %d.0280, %.
    %shl101 = shl i32 %d.0280, %.286
    %or102 = or i32 %shr100, %shl101
    store i32 %or99, i32* %ptr0
    store i32 %or102, i32* %ptr1
    ret void
}

...but I'm trying to kill the setcc bool math sooner rather than later.

By matching a larger pattern that includes both the low-bit mask and the trailing add/sub, 
we can create a universally good fold because we always eliminate the condition code 
intermediate value.

Here are Alive proofs for these (currently instcombine folds the 'add' variants, but 
misses the 'sub' patterns):
https://rise4fun.com/Alive/Gsyp

Name: sub of zext cmp mask
  %a = and i8 %x, 1
  %c = icmp eq i8 %a, 0
  %z = zext i1 %c to i32
  %r = sub i32 C1, %z
  =>
  %optional_cast = zext i8 %a to i32
  %r = add i32 %optional_cast, C1-1

Name: add of zext cmp mask
  %a = and i32 %x, 1
  %c = icmp eq i32 %a, 0
  %z = zext i1 %c to i8
  %r = add i8 %z, C1
  =>
  %optional_cast = trunc i32 %a to i8
  %r = sub i8 C1+1, %optional_cast

All of the tests look like improvements or neutral to me. But it is possible that x86 
test+set+bitop is better than what we now show here. I suspect we could do better by 
adding another fold for the 'sub' variants.

We start with select-of-constant in IR in the larger motivating test, so that's why I 
included tests with selects. Proofs for those variants:
https://rise4fun.com/Alive/Bx1

Name: true const is bigger
Pre: C2 == (C1 + 1)
  %a = and i8 %x, 1
  %c = icmp eq i8 %a, 0
  %r = select i1 %c, i64 C2, i64 C1
  =>
  %z = zext i8 %a to i64
  %r = sub i64 C2, %z

Name: false const is bigger
Pre: C2 == (C1 + 1)
  %a = and i8 %x, 1
  %c = icmp eq i8 %a, 0
  %r = select i1 %c, i64 C1, i64 C2
  =>
  %z = zext i8 %a to i64
  %r = add i64 C1, %z

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

llvm-svn: 335433
2018-06-24 14:37:30 +00:00
..
Analysis [CostModel][AArch64] Add some initial costs for SK_Select and SK_PermuteSingleSrc 2018-06-22 09:45:31 +00:00
Assembler [ThinLTO] Fix a few more test match issues 2018-05-26 03:50:29 +00:00
Bindings [LLVM-C] [OCaml] Remove LLVMAddBBVectorizePass 2018-05-28 16:58:10 +00:00
Bitcode [ThinLTO] Fix a few more test match issues 2018-05-26 03:50:29 +00:00
BugPoint
CodeGen [DAGCombiner] eliminate setcc bool math when input is low-bit of some value 2018-06-24 14:37:30 +00:00
DebugInfo [DebugInfo] Make sure all DBG_VALUEs' reguse operands have IsDebug property 2018-06-21 10:03:34 +00:00
Examples
ExecutionEngine [RuntimeDyld] Implement the ELF PIC large code model relocations 2018-06-22 23:53:22 +00:00
Feature Restore the LoopInstSimplify pass, reverting r327329 that removed it. 2018-05-25 01:32:36 +00:00
FileCheck
Instrumentation Revert r335306 (and r335314) - the Call Graph Profile pass. 2018-06-22 05:33:57 +00:00
Integer
JitListener
LTO IRMover: Account for matching types present across modules 2018-06-20 16:50:56 +00:00
Linker
MC [X86] Make %eiz usage in 64-bit mode, force a 0x67 address size prefix. Fix some test CHECK lines. 2018-06-23 06:15:04 +00:00
Object [ELF] Change isSectionData to exclude SHF_EXECINSTR 2018-06-23 00:15:33 +00:00
ObjectYAML Resubmit [pdb] Change /DEBUG:GHASH to emit 8 byte hashes." 2018-05-17 22:55:15 +00:00
Other Revert r335306 (and r335314) - the Call Graph Profile pass. 2018-06-22 05:33:57 +00:00
SafepointIRVerifier SafepointIRVerifier is made unreachable block tolerant 2018-05-23 05:54:55 +00:00
SymbolRewriter
TableGen [IR] Split Intrinsics.inc into enums and implementations 2018-06-23 02:02:38 +00:00
ThinLTO/X86
Transforms Fix invariant fdiv hoisting in LICM 2018-06-23 04:01:28 +00:00
Unit
Verifier Revert r335306 (and r335314) - the Call Graph Profile pass. 2018-06-22 05:33:57 +00:00
YAMLParser
tools [llvm-mt] Use WithColor for printing errors. 2018-06-23 16:49:07 +00:00
.clang-format
CMakeLists.txt
TestRunner.sh
lit.cfg.py [LIT] Enable testing of LLVM gold plugin on Mac OS X 2018-06-20 15:32:47 +00:00
lit.site.cfg.py.in