diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp --- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp +++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp @@ -934,13 +934,8 @@ size_t ConstantStrSize = ConstantStr.size(); // Trivial cases are optimized during inst combine - if (ConstantStrSize == 0) { + if (ConstantStrSize == 0 || ConstantStrSize > 2) return false; - } - - if (ConstantStrSize > 2) { - return false; - } // Check if strcmp result is only used in a comparison with zero if (!isOnlyUsedInZeroComparison(CI)) @@ -960,7 +955,7 @@ // For strcmp(P, "xy") do the following transformation: // // (before) - // dst = strcmp(P, "x") + // dst = strcmp(P, "xy") // // (after) // v0 = P[0] - 'x' @@ -1000,19 +995,19 @@ static_cast(ConstantStr[CharacterIndexToCheck])); Value *CharacterSub = B.CreateNSWSub(StrCharacterValue, ConstantStrCharacterValue); - Value *IsCharacterSubZero = + Value *CharacterSubIsZero = B.CreateICmpEQ(CharacterSub, ConstantInt::get(RetType, 0)); - BasicBlock *IsCharacterSubZeroBB = + BasicBlock *CharacterSubIsZeroBB = BasicBlock::Create(B.getContext(), "strcmp_expand_sub_is_zero", InitialBB->getParent(), JoinBlock); - B.CreateCondBr(IsCharacterSubZero, IsCharacterSubZeroBB, JoinBlock); + B.CreateCondBr(CharacterSubIsZero, CharacterSubIsZeroBB, JoinBlock); ResultPHI->addIncoming(CharacterSub, B.GetInsertBlock()); DTUpdates.emplace_back(DominatorTree::Insert, B.GetInsertBlock(), - IsCharacterSubZeroBB); + CharacterSubIsZeroBB); - B.SetInsertPoint(IsCharacterSubZeroBB); - DTUpdates.emplace_back(DominatorTree::Insert, IsCharacterSubZeroBB, + B.SetInsertPoint(CharacterSubIsZeroBB); + DTUpdates.emplace_back(DominatorTree::Insert, CharacterSubIsZeroBB, JoinBlock); }