Author: Simon Pilgrim Date: 2021-01-05T11:01:10Z New Revision: 313d982df65a7a8f1da2da5f0e03e6b6e301ce3c
URL: https://github.com/llvm/llvm-project/commit/313d982df65a7a8f1da2da5f0e03e6b6e301ce3c DIFF: https://github.com/llvm/llvm-project/commit/313d982df65a7a8f1da2da5f0e03e6b6e301ce3c.diff LOG: [IR] Add ConstantInt::getBool helpers to wrap getTrue/getFalse. Added: Modified: llvm/include/llvm/IR/Constants.h llvm/lib/IR/Constants.cpp llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp Removed: ################################################################################ diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h index 3fbbf53c29b4..ac802232c23d 100644 --- a/llvm/include/llvm/IR/Constants.h +++ b/llvm/include/llvm/IR/Constants.h @@ -88,8 +88,10 @@ class ConstantInt final : public ConstantData { static ConstantInt *getTrue(LLVMContext &Context); static ConstantInt *getFalse(LLVMContext &Context); + static ConstantInt *getBool(LLVMContext &Context, bool V); static Constant *getTrue(Type *Ty); static Constant *getFalse(Type *Ty); + static Constant *getBool(Type *Ty, bool V); /// If Ty is a vector type, return a Constant with a splat of the given /// value. Otherwise return a ConstantInt for the given value. diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 82a5f9db0bf7..a38302d17937 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -815,6 +815,10 @@ ConstantInt *ConstantInt::getFalse(LLVMContext &Context) { return pImpl->TheFalseVal; } +ConstantInt *ConstantInt::getBool(LLVMContext &Context, bool V) { + return V ? getTrue(Context) : getFalse(Context); +} + Constant *ConstantInt::getTrue(Type *Ty) { assert(Ty->isIntOrIntVectorTy(1) && "Type not i1 or vector of i1."); ConstantInt *TrueC = ConstantInt::getTrue(Ty->getContext()); @@ -831,6 +835,10 @@ Constant *ConstantInt::getFalse(Type *Ty) { return FalseC; } +Constant *ConstantInt::getBool(Type *Ty, bool V) { + return V ? getTrue(Ty) : getFalse(Ty); +} + // Get a ConstantInt from an APInt. ConstantInt *ConstantInt::get(LLVMContext &Context, const APInt &V) { // get an existing value or the insertion position diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 83b310bfcd05..87d4b40a9a64 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -5037,11 +5037,9 @@ Instruction *InstCombinerImpl::foldICmpUsingKnownBits(ICmpInst &I) { llvm_unreachable("Unknown icmp opcode!"); case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_NE: { - if (Op0Max.ult(Op1Min) || Op0Min.ugt(Op1Max)) { - return Pred == CmpInst::ICMP_EQ - ? replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())) - : replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); - } + if (Op0Max.ult(Op1Min) || Op0Min.ugt(Op1Max)) + return replaceInstUsesWith( + I, ConstantInt::getBool(I.getType(), Pred == CmpInst::ICMP_NE)); // If all bits are known zero except for one, then we know at most one bit // is set. If the comparison is against zero, then this is a check to see if _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits