[InstSimplify] fold select with implied condition
authorSanjay Patel <spatel@rotateright.com>
Thu, 29 Nov 2018 18:44:39 +0000 (18:44 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 29 Nov 2018 18:44:39 +0000 (18:44 +0000)
commitd802270808c9daa9bf689560f2da652fb907b5e8
treec629598b354222f6aea02f4cf8e16ef1a4aa4cc3
parentb74d6368974c4b4b2913c1c20bd8c632c6492cb6
[InstSimplify] fold select with implied condition

This is an almost direct move of the functionality from InstCombine to
InstSimplify. There's no reason not to do this in InstSimplify because
we never create a new value with this transform.

(There's a question of whether any dominance-based transform belongs in
either of these passes, but that's a separate issue.)

I've changed 1 of the conditions for the fold (1 of the blocks for the
branch must be the block we started with) into an assert because I'm not
sure how that could ever be false.

We need 1 extra check to make sure that the instruction itself is in a
basic block because passes other than InstCombine may be using InstSimplify
as an analysis on values that are not wired up yet.

The 3-way compare changes show that InstCombine has some kind of
phase-ordering hole. Otherwise, we would have already gotten the intended
final result that we now show here.

llvm-svn: 347896
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/unrecognized_three-way-comparison.ll
llvm/test/Transforms/InstSimplify/select-implied.ll [moved from llvm/test/Transforms/InstCombine/select-implied.ll with 94% similarity]