[PATCH] D112108: [InstCombine] Fold `(a & ~b) & ~c` to `a & ~(b | c)`
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 20 11:53:48 PDT 2021
spatel added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2018-2020
+ if (match(Op0, m_c_And(m_Value(A), m_Not(m_Value(B)))))
+ if (match(Op1, m_Not(m_Value(C))))
+ if (Op0->hasOneUse())
----------------
You can fold the one-use check into the 1st match with m_OneUse(). Could also use && for the match clauses instead of nested ifs to make the structure more like the code above here.
================
Comment at: llvm/test/Transforms/InstCombine/and-xor-or.ll:556
define i32 @not_and_and_not_commute1(i32 %a0, i32 %b, i32 %c) {
; CHECK-LABEL: @not_and_and_not_commute1(
----------------
In this test, we do not want to thwart complexity-based canonicalization - we want `%a` to remain as op1, so you don't need the extra `sdiv`.
================
Comment at: llvm/test/Transforms/InstCombine/and-xor-or.ll:574
define i32 @not_and_and_not_commute2(i32 %a0, i32 %b, i32 %c) {
; CHECK-LABEL: @not_and_and_not_commute2(
----------------
This one is going to be commuted no matter what we do. It's fine to include this for completeness, but let's have it show another variation - add an extra use for `%not2` with something like:
call void @use(i32 %not2)
Similarly, we should have a negative test for the transform when `%and1` has another use.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112108/new/
https://reviews.llvm.org/D112108
More information about the llvm-commits
mailing list