[llvm] [InstCombine] Fold comparison of adding two z/sext booleans (PR #67895)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 2 02:33:17 PDT 2023
================
@@ -2895,19 +2896,86 @@ Instruction *InstCombinerImpl::foldICmpSubConstant(ICmpInst &Cmp,
return new ICmpInst(SwappedPred, Add, ConstantInt::get(Ty, ~C));
}
+static Value *createLogicFromTable(const std::bitset<4> &Table, Value *Op0,
+ Value *Op1, IRBuilderBase &Builder) {
+ switch (Table.to_ulong()) {
+ case 0: // 0 0 0 0
+ return Builder.getFalse();
+ case 1: // 0 0 0 1
+ return Builder.CreateNot(Builder.CreateOr(Op0, Op1));
+ case 2: // 0 0 1 0
+ return Builder.CreateAnd(Builder.CreateNot(Op0), Op1);
+ case 3: // 0 0 1 1
+ return Op1;
+ case 4: // 0 1 0 0
+ return Builder.CreateAnd(Op0, Builder.CreateNot(Op1));
+ case 5: // 0 1 0 1
+ return Op0;
+ case 6: // 0 1 1 0
+ return Builder.CreateXor(Op0, Op1);
+ case 7: // 0 1 1 1
+ return Builder.CreateNot(Builder.CreateAnd(Op0, Op1));
+ case 8: // 1 0 0 0
+ return Builder.CreateAnd(Op0, Op1);
+ case 9: // 1 0 0 1
+ return Builder.CreateNot(Builder.CreateXor(Op0, Op1));
+ case 10: // 1 0 1 0
+ return Builder.CreateNot(Op1);
+ case 11: // 1 0 1 1
+ return Builder.CreateOr(Builder.CreateNot(Op0), Op1);
+ case 12: // 1 1 0 0
+ return Builder.CreateNot(Op1);
+ case 13: // 1 1 0 1
+ return Builder.CreateOr(Op0, Builder.CreateNot(Op1));
+ case 14: // 1 1 1 0
+ return Builder.CreateOr(Op0, Op1);
+ case 15: // 1 1 1 1
+ return Builder.getTrue();
----------------
nikic wrote:
Add `default` with `llvm_unreachable`.
https://github.com/llvm/llvm-project/pull/67895
More information about the llvm-commits
mailing list