Reduce the complexity of the signbit/branch test functions.

llvm-svn: 306779
This commit is contained in:
Eric Christopher 2017-06-30 01:35:31 +00:00
parent 837755cf8b
commit 710c1c8faa
1 changed files with 3 additions and 3 deletions

View File

@ -112,10 +112,10 @@ static bool subWithOverflow(Constant *&Result, Constant *In1,
/// Given an icmp instruction, return true if any use of this comparison is a
/// branch on sign bit comparison.
static bool isBranchOnSignBitCheck(ICmpInst &I, bool isSignBit) {
static bool hasBranchUse(ICmpInst &I) {
for (auto *U : I.users())
if (isa<BranchInst>(U))
return isSignBit;
return true;
return false;
}
@ -1448,7 +1448,7 @@ Instruction *InstCombiner::foldICmpWithConstant(ICmpInst &Cmp) {
// of a test and branch. So we avoid canonicalizing in such situations
// because test and branch instruction has better branch displacement
// than compare and branch instruction.
if (!isBranchOnSignBitCheck(Cmp, IsSignBit) && !Cmp.isEquality()) {
if (!(IsSignBit && hasBranchUse(Cmp)) && !Cmp.isEquality()) {
if (auto *AI = Intersection.getSingleElement())
return new ICmpInst(ICmpInst::ICMP_EQ, X, Builder->getInt(*AI));
if (auto *AD = Difference.getSingleElement())