[PATCH] D159464: [InstCombine] Fold comparison of adding two zero extended booleans

Mohamed Atef via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 8 04:03:58 PDT 2023


elhewaty added a comment.

// zext i1 X + zext i1 Y != 0 --> or i1 X, Y
https://alive2.llvm.org/ce/z/Rg3mm7

// zext i1 Op0 + zext i1 Op1 != 1 --> !(xor i1 Op0, Op1)
https://alive2.llvm.org/ce/z/WFyF_2

// zext i1 Op0 + zext i1 Op1 != 2 --> !(and i1 Op0, Op1)
https://alive2.llvm.org/ce/z/-QgaLR

// sext i1 Op0 + sext i1 Op1 != 0 --> or i1 Op0, Op1
https://alive2.llvm.org/ce/z/oPXhLY

// sext i1 Op0 + sext i1 Op1 != 1 --> true
https://alive2.llvm.org/ce/z/xTWVYh

// sext i1 Op0 + sext i1 Op1 != 2 --> true
https://alive2.llvm.org/ce/z/GoroRZ

// sext i1 Op0 + zext i1 Op1 != 0 --> xor i1 Op0, Op1
https://alive2.llvm.org/ce/z/mN7g3V

// sext i1 Op0 + zext i1 Op1 != 1 --> Op0 | (!Op1)
https://alive2.llvm.org/ce/z/FT_8iD

// sext i1 Op0 + zext i1 Op1 != 2 --> true
https://alive2.llvm.org/ce/z/ih8K7-



================
Comment at: llvm/test/Transforms/InstCombine/icmp-add.ll:36
+}
+
 define i1 @test1(i32 %a) {
----------------
arsenm wrote:
> elhewaty wrote:
> > arsenm wrote:
> > > Add tests showing the multiple use rejections
> > Can you please explain what do you mean by multiple use rejections? 
> You check (m_OneUse, so should have some negative tests where there is an additional use (e.g a store of the intermediate value). Similarly you don’t have negative tests for other compare types. You could handle ne/lt/ge but should at least have tests for them even if left unhandled 
Okay, I will do my best.
But I am just waiting for the code to be fully accepted, then I will try to write tests.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159464/new/

https://reviews.llvm.org/D159464



More information about the llvm-commits mailing list