Skip to content

Commit f1eda23

Browse files
committed
Added InstCombine Transform for ((B | C) & A) | B -> B | (A & C)
Transform ((B | C) & A) | B --> B | (A & C) Z3 Link: http://rise4fun.com/Z3/hP6p Patch by Sonam Kumari! Differential Revision: http://reviews.llvm.org/D4865 llvm-svn: 215619
1 parent ad2986e commit f1eda23

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,10 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
21242124
if (Op0->hasOneUse() || cast<BinaryOperator>(Op0)->hasOneUse())
21252125
return BinaryOperator::CreateOr(Op1, C);
21262126

2127+
// ((B | C) & A) | B -> B | (A & C)
2128+
if (match(Op0, m_And(m_Or(m_Specific(Op1), m_Value(C)), m_Value(A))))
2129+
return BinaryOperator::CreateOr(Op1, Builder->CreateAnd(A, C));
2130+
21272131
// (X >> Z) | (Y >> Z) -> (X|Y) >> Z for all shifts.
21282132
if (BinaryOperator *SI1 = dyn_cast<BinaryOperator>(Op1)) {
21292133
if (BinaryOperator *SI0 = dyn_cast<BinaryOperator>(Op0))

llvm/test/Transforms/InstCombine/or.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,14 @@ define i32 @test44(i32 %a, i32 %b) {
469469
%or = or i32 %xor, %and
470470
ret i32 %or
471471
}
472+
473+
define i32 @test45(i32 %x, i32 %y, i32 %z) {
474+
; CHECK-LABEL: test45(
475+
; CHECK-NEXT: %1 = and i32 %x, %z
476+
; CHECK-NEXT: %or1 = or i32 %1, %y
477+
; CHECK-NEXT: ret i32 %or1
478+
%or = or i32 %y, %z
479+
%and = and i32 %x, %or
480+
%or1 = or i32 %and, %y
481+
ret i32 %or1
482+
}

0 commit comments

Comments
 (0)