[InstCombine] Optimize icmp-select-icmp
authorGerolf Hoflehner <ghoflehner@apple.com>
Wed, 1 Oct 2014 00:13:22 +0000 (00:13 +0000)
committerGerolf Hoflehner <ghoflehner@apple.com>
Wed, 1 Oct 2014 00:13:22 +0000 (00:13 +0000)
commit2318c2f28d925f31e90498ab0cb0c2b97bb60292
tree8890921f09a684201109acb9a587ff781d20a3e9
parent8f70c4827ac6869d25336f936b88cffc4946d5d5
[InstCombine] Optimize icmp-select-icmp

In special cases select instructions can be eliminated by
replacing them with a cheaper bitwise operation even when the
select result is used outside its home block. The instances implemented
are patterns like
    %x=icmp.eq
    %y=select %x,%r, null
    %z=icmp.eq|neq %y, null
    br %z,true, false
==> %x=icmp.ne
    %y=icmp.eq %r,null
    %z=or %x,%y
    br %z,true,false
The optimization is integrated into the instruction
combiner and performed only when all uses of the select result can
be replaced by the select operand proper. For this dominator information
is used and dominance is now a required analysis pass in the combiner.
The optimization itself is iterative. The critical step is to replace the
select result with the non-constant select operand. So the select becomes
local and the combiner iteratively works out simpler code pattern and
eventually eliminates the select.

rdar://17853760

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218721 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombine.h
lib/Transforms/InstCombine/InstCombineCompares.cpp
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/pr12338.ll
test/Transforms/InstCombine/select-cmp-br.ll [new file with mode: 0644]