Skip to content

Commit

Permalink
[InstCombine] Use ConstantInt::getBool instead of `Constant::getInt…
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Sep 16, 2023
1 parent b423e1f commit 5163319
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5054,14 +5054,10 @@ InstCombinerImpl::foldICmpWithMinMaxImpl(Instruction &I,
case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_SGE:
case ICmpInst::ICMP_UGE: {
auto FoldIntoConstant = [&](bool Value) {
return replaceInstUsesWith(
I, Constant::getIntegerValue(
I.getType(), APInt(1U, static_cast<uint64_t>(Value))));
};
auto FoldIntoCmpYZ = [&]() -> Instruction * {
if (CmpYZ.has_value())
return FoldIntoConstant(*CmpYZ);
return replaceInstUsesWith(I,
ConstantInt::getBool(I.getType(), *CmpYZ));
return ICmpInst::Create(Instruction::ICmp, Pred, Y, Z);
};

Expand All @@ -5073,7 +5069,7 @@ InstCombinerImpl::foldICmpWithMinMaxImpl(Instruction &I,
// min(X, Y) <= Z X <= Z true
// max(X, Y) > Z X > Z true
// max(X, Y) >= Z X >= Z true
return FoldIntoConstant(true);
return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType()));
} else {
// Expr Fact Result
// max(X, Y) < Z X < Z Y < Z
Expand All @@ -5096,7 +5092,7 @@ InstCombinerImpl::foldICmpWithMinMaxImpl(Instruction &I,
// max(X, Y) <= Z X > Z false
// min(X, Y) > Z X <= Z false
// min(X, Y) >= Z X < Z false
return FoldIntoConstant(false);
return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType()));
}
}
break;
Expand Down

0 comments on commit 5163319

Please sign in to comment.