[PATCH] D113141: [InstCombine] Relax and reorganize one use checks in the ~(a | b) & c
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 9 13:05:01 PST 2021
spatel added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2815
// (~(A | B) & C) | ~(A | C) --> ~((B & C) | A)
- if (match(Op1, m_Not(m_c_Or(m_Specific(A), m_Specific(C)))))
+ if (match(Op1, m_OneUse(m_Not(m_c_Or(m_Specific(A), m_Specific(C))))))
return BinaryOperator::CreateNot(
----------------
This isn't strong enough to prevent the transform from ending up with more instructions than we started with - we are creating 3 instructions, so we need to eliminate at least 2 intermediate values plus the final value.
I think we'd be ok if we have 2 m_OneUse checks in this match (similar to the transform above this).
Please add a test like this to confirm:
```
define i32 @or_and_not_not_2_extra_uses(i32 %a, i32 %b, i32 %c) {
%or1 = or i32 %b, %a
call void @use(i32 %or1)
%not1 = xor i32 %or1, -1
%or2 = or i32 %a, %c
%not2 = xor i32 %or2, -1
%and = and i32 %not2, %b
call void @use(i32 %and)
%or3 = or i32 %not1, %and
ret i32 %or3
}
```
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113141/new/
https://reviews.llvm.org/D113141
More information about the llvm-commits
mailing list