mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-28 22:24:28 +00:00
InstCombine: Combine (X | Y) - X to (~X & Y)
This implements the transformation from (X | Y) - X to (~X & Y). Differential Revision: http://reviews.llvm.org/D5791 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221129 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1630,6 +1630,15 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
|
||||
return BinaryOperator::CreateAnd(A, B);
|
||||
}
|
||||
|
||||
if (Op0->hasOneUse()) {
|
||||
Value *Y = nullptr;
|
||||
// ((X | Y) - X) --> (~X & Y)
|
||||
if (match(Op0, m_Or(m_Value(Y), m_Specific(Op1))) ||
|
||||
match(Op0, m_Or(m_Specific(Op1), m_Value(Y))))
|
||||
return BinaryOperator::CreateAnd(
|
||||
Y, Builder->CreateNot(Op1, Op1->getName() + ".not"));
|
||||
}
|
||||
|
||||
if (Op1->hasOneUse()) {
|
||||
Value *X = nullptr, *Y = nullptr, *Z = nullptr;
|
||||
Constant *C = nullptr;
|
||||
|
@ -540,3 +540,13 @@ define i32 @test45(i32 %x, i32 %y) {
|
||||
; CHECK-NEXT: %sub = and i32 %x, %y
|
||||
; CHECK: ret i32 %sub
|
||||
}
|
||||
|
||||
define i32 @test46(i32 %x, i32 %y) {
|
||||
%or = or i32 %x, %y
|
||||
%sub = sub i32 %or, %x
|
||||
ret i32 %sub
|
||||
; CHECK-LABEL: @test46(
|
||||
; CHECK-NEXT: %x.not = xor i32 %x, -1
|
||||
; CHECK-NEXT: %sub = and i32 %y, %x.not
|
||||
; CHECK: ret i32 %sub
|
||||
}
|
||||
|
Reference in New Issue
Block a user