[InstCombine] Generalize sub of selects optimization to all BinaryOperators

This exposes further optimization opportunities if the selects are
correlated.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242235 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer
2015-07-14 22:39:23 +00:00
parent d640af829c
commit 137ad1ded9
3 changed files with 37 additions and 26 deletions

View File

@@ -395,3 +395,13 @@ define i8 @add_of_mul(i8 %x, i8 %y, i8 %z) {
%sum = add nsw i8 %mA, %mB
ret i8 %sum
}
define i32 @add_of_selects(i1 %A, i32 %B) {
%sel0 = select i1 %A, i32 0, i32 -2
%sel1 = select i1 %A, i32 %B, i32 2
%add = add i32 %sel0, %sel1
ret i32 %add
; CHECK-LABEL: @add_of_selects(
; CHECK-NEXT: %[[sel:.*]] = select i1 %A, i32 %B, i32 0
; CHECK-NEXT: ret i32 %[[sel]]
}