llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-llvm-transforms Author: Aiden Grossman (boomanaiden154) <details> <summary>Changes</summary> Our internal ablation study on the set of checks up to 2-11-2026 has finished, so we can remove any fixes that are older than that. --- Full diff: https://github.com/llvm/llvm-project/pull/222409.diff 6 Files Affected: - (modified) llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (+8-13) - (modified) llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp (+8-14) - (modified) llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (+1-6) - (modified) llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (+1-7) - (modified) llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp (+12-25) - (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+15-29) ``````````diff diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index cd7fed74a4cf3..ba82d282c2305 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1311,8 +1311,7 @@ static Value *foldAndOrOfICmpsWithConstEq(ICmpInst *Cmp0, ICmpInst *Cmp1, SubstituteCmp = Builder.CreateICmp(Pred1, Y, C); } if (IsLogical) { - Instruction *MDFrom = - ProfcheckDisableMetadataFixes && isa<SelectInst>(I) ? nullptr : &I; + Instruction *MDFrom = isa<SelectInst>(I) ? &I : nullptr; return IsAnd ? Builder.CreateLogicalAnd(Cmp0, SubstituteCmp, "", MDFrom) : Builder.CreateLogicalOr(Cmp0, SubstituteCmp, "", MDFrom); } @@ -2444,8 +2443,7 @@ Value *InstCombinerImpl::reassociateBooleanAndOr(Value *LHS, Value *X, Value *Y, else if (Value *Res = foldBooleanAndOr(LHS, Y, I, IsAnd, /*IsLogical=*/false)) Folded = RHSIsLogical ? Builder.CreateLogicalOp(Opcode, X, Res) : Builder.CreateBinOp(Opcode, X, Res); - if (SelectInst *SI = dyn_cast_or_null<SelectInst>(Folded); - SI != nullptr && !ProfcheckDisableMetadataFixes) + if (SelectInst *SI = dyn_cast_or_null<SelectInst>(Folded); SI != nullptr) // If the bop I was originally a lop, we could recover branch weight // information using that lop's weights. However, InstCombine usually // replaces the lop with a bop by the time we get here, deleting the branch @@ -5118,8 +5116,7 @@ bool InstCombinerImpl::sinkNotIntoLogicalOp(Instruction &I) { NewLogicOp = Builder.CreateBinOp(NewOpc, Op0, Op1, I.getName() + ".not"); } else { NewLogicOp = - Builder.CreateLogicalOp(NewOpc, Op0, Op1, I.getName() + ".not", - ProfcheckDisableMetadataFixes ? nullptr : &I); + Builder.CreateLogicalOp(NewOpc, Op0, Op1, I.getName() + ".not", &I); if (SelectInst *SI = dyn_cast<SelectInst>(NewLogicOp)) SI->swapProfMetadata(); } @@ -5200,9 +5197,8 @@ Instruction *InstCombinerImpl::foldNot(BinaryOperator &I) { } if (match(NotOp, m_OneUse(m_LogicalAnd(m_Not(m_Value(X)), m_Value(Y))))) { Value *NotY = Builder.CreateNot(Y, Y->getName() + ".not"); - SelectInst *SI = SelectInst::Create( - X, ConstantInt::getTrue(Ty), NotY, "", nullptr, - ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(NotOp)); + SelectInst *SI = SelectInst::Create(X, ConstantInt::getTrue(Ty), NotY, "", + nullptr, cast<Instruction>(NotOp)); SI->swapProfMetadata(); return SI; } @@ -5215,9 +5211,8 @@ Instruction *InstCombinerImpl::foldNot(BinaryOperator &I) { } if (match(NotOp, m_OneUse(m_LogicalOr(m_Not(m_Value(X)), m_Value(Y))))) { Value *NotY = Builder.CreateNot(Y, Y->getName() + ".not"); - SelectInst *SI = SelectInst::Create( - X, NotY, ConstantInt::getFalse(Ty), "", nullptr, - ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(NotOp)); + SelectInst *SI = SelectInst::Create(X, NotY, ConstantInt::getFalse(Ty), "", + nullptr, cast<Instruction>(NotOp)); SI->swapProfMetadata(); return SI; } @@ -5699,7 +5694,7 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) { if (NeedFreeze) A = Builder.CreateFreeze(A); Value *NotB = Builder.CreateNot(B); - return MDFrom == nullptr || ProfcheckDisableMetadataFixes + return MDFrom == nullptr ? createSelectInstWithUnknownProfile(A, NotB, C) : SelectInst::Create(A, NotB, C, "", nullptr, MDFrom); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index a6e5bd6296d3f..a7015a9ddff1b 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -42,10 +42,6 @@ using namespace PatternMatch; // How many times is a select replaced by one of its operands? STATISTIC(NumSel, "Number of select opts"); -namespace llvm { -extern cl::opt<bool> ProfcheckDisableMetadataFixes; -} - /// Compute Result = In1+In2, returning true if the result overflowed for this /// type. static bool addWithOverflow(APInt &Result, const APInt &In1, const APInt &In2, @@ -4548,8 +4544,7 @@ Instruction *InstCombinerImpl::foldSelectICmp(CmpPredicate Pred, SelectInst *SI, Op1 = Builder.CreateICmp(Pred, SI->getOperand(1), RHS, I.getName()); if (!Op2) Op2 = Builder.CreateICmp(Pred, SI->getOperand(2), RHS, I.getName()); - return SelectInst::Create(SI->getOperand(0), Op1, Op2, "", nullptr, - ProfcheckDisableMetadataFixes ? nullptr : SI); + return SelectInst::Create(SI->getOperand(0), Op1, Op2, "", nullptr, SI); } return nullptr; @@ -6127,8 +6122,7 @@ struct OffsetResult { case OffsetKind::Value: return V0; case OffsetKind::Select: - return Builder.CreateSelect( - V0, V1, V2, "", ProfcheckDisableMetadataFixes ? nullptr : MDFrom); + return Builder.CreateSelect(V0, V1, V2, "", MDFrom); } llvm_unreachable("Unknown OffsetKind enum"); } @@ -8131,16 +8125,16 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) { // Check whether comparison of TrueValues can be simplified if (Value *Res = simplifyICmpInst(Pred, A, C, SQ)) { Value *NewICMP = Builder.CreateICmp(Pred, B, D); - return SelectInst::Create( - Cond, Res, NewICMP, /*NameStr=*/"", /*InsertBefore=*/nullptr, - ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(Op0)); + return SelectInst::Create(Cond, Res, NewICMP, /*NameStr=*/"", + /*InsertBefore=*/nullptr, + cast<Instruction>(Op0)); } // Check whether comparison of FalseValues can be simplified if (Value *Res = simplifyICmpInst(Pred, B, D, SQ)) { Value *NewICMP = Builder.CreateICmp(Pred, A, C); - return SelectInst::Create( - Cond, NewICMP, Res, /*NameStr=*/"", /*InsertBefore=*/nullptr, - ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(Op0)); + return SelectInst::Create(Cond, NewICMP, Res, /*NameStr=*/"", + /*InsertBefore=*/nullptr, + cast<Instruction>(Op0)); } } } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 94b4332020834..8e2a0c5376d8e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -27,10 +27,6 @@ using namespace PatternMatch; #define DEBUG_TYPE "instcombine" -namespace llvm { -extern cl::opt<bool> ProfcheckDisableMetadataFixes; -} - STATISTIC(NumDeadStore, "Number of dead stores eliminated"); STATISTIC(NumGlobalCopies, "Number of allocas copied from constant global"); @@ -1184,8 +1180,7 @@ Instruction *InstCombinerImpl::visitLoadInst(LoadInst &LI) { // poison-generating metadata. V1->copyMetadata(LI, Metadata::PoisonGeneratingIDs); V2->copyMetadata(LI, Metadata::PoisonGeneratingIDs); - return SelectInst::Create(SI->getCondition(), V1, V2, "", nullptr, - ProfcheckDisableMetadataFixes ? nullptr : SI); + return SelectInst::Create(SI->getCondition(), V1, V2, "", nullptr, SI); } } } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 128e3e3dcdfe8..da0254cbb196e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -41,10 +41,6 @@ using namespace llvm; using namespace PatternMatch; -namespace llvm { -extern cl::opt<bool> ProfcheckDisableMetadataFixes; -} - /// The specific integer value is used in a context where it is known to be /// non-zero. If this allows us to simplify the computation, do so and return /// the new operand, otherwise return null. @@ -1721,9 +1717,7 @@ Value *InstCombinerImpl::takeLog2(Value *Op, unsigned Depth, bool AssumeNonZero, if (Value *LogY = takeLog2(SI->getOperand(2), Depth, AssumeNonZero, DoFold)) return IfFold([&]() { - return Builder.CreateSelect(SI->getOperand(0), LogX, LogY, "", - ProfcheckDisableMetadataFixes ? nullptr - : SI); + return Builder.CreateSelect(SI->getOperand(0), LogX, LogY, "", SI); }); // log2(umin(X, Y)) -> umin(log2(X), log2(Y)) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 4b01334f8634c..4f0c21831cb4c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -3858,18 +3858,16 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) { // select a, false, b -> select !a, b, false if (match(TrueVal, m_Specific(Zero))) { Value *NotCond = Builder.CreateNot(CondVal, "not." + CondVal->getName()); - Instruction *MDFrom = ProfcheckDisableMetadataFixes ? nullptr : &SI; - SelectInst *NewSI = - SelectInst::Create(NotCond, FalseVal, Zero, "", nullptr, MDFrom); + SelectInst *NewSI = SelectInst::Create(NotCond, FalseVal, Zero, "", nullptr, + /*MDFrom=*/&SI); NewSI->swapProfMetadata(); return NewSI; } // select a, b, true -> select !a, true, b if (match(FalseVal, m_Specific(One))) { Value *NotCond = Builder.CreateNot(CondVal, "not." + CondVal->getName()); - Instruction *MDFrom = ProfcheckDisableMetadataFixes ? nullptr : &SI; SelectInst *NewSI = - SelectInst::Create(NotCond, One, TrueVal, "", nullptr, MDFrom); + SelectInst::Create(NotCond, One, TrueVal, "", nullptr, /*MDFrom=*/&SI); NewSI->swapProfMetadata(); return NewSI; } @@ -3879,9 +3877,8 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) { if (match(&SI, m_LogicalAnd(m_Not(m_Value(A)), m_Not(m_Value(B)))) && (CondVal->hasOneUse() || TrueVal->hasOneUse()) && !match(A, m_ConstantExpr()) && !match(B, m_ConstantExpr())) { - Instruction *MDFrom = ProfcheckDisableMetadataFixes ? nullptr : &SI; SelectInst *NewSI = - cast<SelectInst>(Builder.CreateSelect(A, One, B, "", MDFrom)); + cast<SelectInst>(Builder.CreateSelect(A, One, B, "", /*MDFrom=*/&SI)); NewSI->swapProfMetadata(); return BinaryOperator::CreateNot(NewSI); } @@ -3891,9 +3888,8 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) { if (match(&SI, m_LogicalOr(m_Not(m_Value(A)), m_Not(m_Value(B)))) && (CondVal->hasOneUse() || FalseVal->hasOneUse()) && !match(A, m_ConstantExpr()) && !match(B, m_ConstantExpr())) { - Instruction *MDFrom = ProfcheckDisableMetadataFixes ? nullptr : &SI; SelectInst *NewSI = - cast<SelectInst>(Builder.CreateSelect(A, B, Zero, "", MDFrom)); + cast<SelectInst>(Builder.CreateSelect(A, B, Zero, "", /*MDFrom=*/&SI)); NewSI->swapProfMetadata(); return BinaryOperator::CreateNot(NewSI); } @@ -5045,23 +5041,19 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { // select(C0, select(C1, a, b), b) -> select(C0&&C1, a, b) if (TrueSI->getFalseValue() == FalseVal) { And = Builder.CreateLogicalAnd(CondVal, TrueSI->getCondition(), "", - ProfcheckDisableMetadataFixes ? nullptr - : &SI); + &SI); OtherVal = TrueSI->getTrueValue(); } // select(C0, select(C1, b, a), b) -> select(C0&&!C1, a, b) else if (TrueSI->getTrueValue() == FalseVal) { Value *InvertedCond = Builder.CreateNot(TrueSI->getCondition()); - And = Builder.CreateLogicalAnd(CondVal, InvertedCond, "", - ProfcheckDisableMetadataFixes ? nullptr - : &SI); + And = Builder.CreateLogicalAnd(CondVal, InvertedCond, "", &SI); OtherVal = TrueSI->getFalseValue(); } if (And && OtherVal) { replaceOperand(SI, 0, And); replaceOperand(SI, 1, OtherVal); - if (!ProfcheckDisableMetadataFixes) - setExplicitlyUnknownBranchWeightsIfProfiled(SI, DEBUG_TYPE); + setExplicitlyUnknownBranchWeightsIfProfiled(SI, DEBUG_TYPE); return &SI; } } @@ -5080,23 +5072,19 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { // select(C0, a, select(C1, a, b)) -> select(C0||C1, a, b) if (FalseSI->getTrueValue() == TrueVal) { Or = Builder.CreateLogicalOr(CondVal, FalseSI->getCondition(), "", - ProfcheckDisableMetadataFixes ? nullptr - : &SI); + &SI); OtherVal = FalseSI->getFalseValue(); } // select(C0, a, select(C1, b, a)) -> select(C0||!C1, a, b) else if (FalseSI->getFalseValue() == TrueVal) { Value *InvertedCond = Builder.CreateNot(FalseSI->getCondition()); - Or = Builder.CreateLogicalOr(CondVal, InvertedCond, "", - ProfcheckDisableMetadataFixes ? nullptr - : &SI); + Or = Builder.CreateLogicalOr(CondVal, InvertedCond, "", &SI); OtherVal = FalseSI->getTrueValue(); } if (Or && OtherVal) { replaceOperand(SI, 0, Or); replaceOperand(SI, 2, OtherVal); - if (!ProfcheckDisableMetadataFixes) - setExplicitlyUnknownBranchWeightsIfProfiled(SI, DEBUG_TYPE); + setExplicitlyUnknownBranchWeightsIfProfiled(SI, DEBUG_TYPE); return &SI; } } @@ -5271,8 +5259,7 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { // metadata of the original select as the net effect of this change is to // simplify the conditional. Instruction *MDFrom = nullptr; - if (NewTrueVal == TrueVal && NewFalseVal == FalseVal && - !ProfcheckDisableMetadataFixes) { + if (NewTrueVal == TrueVal && NewFalseVal == FalseVal) { MDFrom = &SI; } return SelectInst::Create(A, NewTrueVal, NewFalseVal, "", nullptr, diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index b877f79a000cf..4b09510933d0c 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -150,10 +150,6 @@ static cl::opt<unsigned> MaxAllocSiteRemovableUsers( cl::desc("Maximum number of users to visit in alloc-site " "removability analysis")); -namespace llvm { -extern cl::opt<bool> ProfcheckDisableMetadataFixes; -} // end namespace llvm - // FIXME: Remove this flag when it is no longer necessary to convert // llvm.dbg.declare to avoid inaccurate debug info. Setting this to false // increases variable availability at the cost of accuracy. Variables that @@ -1132,9 +1128,7 @@ InstCombinerImpl::foldBinOpOfSelectAndCastOfSelectCondition(BinaryOperator &I) { else return nullptr; - SelectInst *SI = ProfcheckDisableMetadataFixes - ? nullptr - : cast<SelectInst>(CastOp == LHS ? RHS : LHS); + SelectInst *SI = cast<SelectInst>(CastOp == LHS ? RHS : LHS); auto NewFoldedConst = [&](bool IsTrueArm, Value *V) { bool IsCastOpRHS = (CastOp == RHS); @@ -1368,9 +1362,7 @@ Value *InstCombinerImpl::SimplifySelectsFeedingBinaryOp(BinaryOperator &I, if (!LHSIsSelect && !RHSIsSelect) return nullptr; - SelectInst *SI = ProfcheckDisableMetadataFixes - ? nullptr - : cast<SelectInst>(LHSIsSelect ? LHS : RHS); + SelectInst *SI = cast<SelectInst>(LHSIsSelect ? LHS : RHS); FastMathFlags FMF; BuilderTy::FastMathFlagGuard Guard(Builder); @@ -1926,9 +1918,7 @@ Instruction *InstCombinerImpl::foldBinOpSelectBinOp(BinaryOperator &Op) { if (!NewTV || !NewFV) return nullptr; - Value *NewSI = - Builder.CreateSelect(SI->getCondition(), NewTV, NewFV, "", - ProfcheckDisableMetadataFixes ? nullptr : SI); + Value *NewSI = Builder.CreateSelect(SI->getCondition(), NewTV, NewFV, "", SI); return BinaryOperator::Create(Op.getOpcode(), NewSI, Input); } @@ -2922,9 +2912,9 @@ Instruction *InstCombinerImpl::visitGEPOfGEP(GetElementPtrInst &GEP, APInt NewFalseVal = *ConstOffset + *FalseVal; Constant *NewTrue = ConstantInt::get(Select->getType(), NewTrueVal); Constant *NewFalse = ConstantInt::get(Select->getType(), NewFalseVal); - Value *NewSelect = Builder.CreateSelect( - Cond, NewTrue, NewFalse, /*Name=*/"", - /*MDFrom=*/(ProfcheckDisableMetadataFixes ? nullptr : Select)); + Value *NewSelect = + Builder.CreateSelect(Cond, NewTrue, NewFalse, /*Name=*/"", + /*MDFrom=*/Select); GEPNoWrapFlags Flags = getMergedGEPNoWrapFlags(*Src, *cast<GEPOperator>(&GEP)); return replaceInstUsesWith(GEP, @@ -3077,9 +3067,8 @@ Value *InstCombiner::getFreelyInvertedImpl(Value *V, bool WillInvertAllUses, if (auto *II = dyn_cast<IntrinsicInst>(V)) return Builder->CreateBinaryIntrinsic( getInverseMinMaxIntrinsic(II->getIntrinsicID()), NotA, NotB); - return Builder->CreateSelect( - Cond, NotA, NotB, "", - ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(V)); + return Builder->CreateSelect(Cond, NotA, NotB, "", + cast<Instruction>(V)); } return NonNull; } @@ -4361,16 +4350,13 @@ Instruction *InstCombinerImpl::visitCondBrInst(CondBrInst &BI) { Value *Or = Builder.CreateLogicalOr(NotX, Y); // Set weights for the new OR select instruction too. - if (!ProfcheckDisableMetadataFixes) { - if (auto *OrInst = dyn_cast<Instruction>(Or)) { - if (auto *CondInst = dyn_cast<Instruction>(Cond)) { - SmallVector<uint32_t> Weights; - if (extractBranchWeights(*CondInst, Weights)) { - assert(Weights.size() == 2 && - "Unexpected number of branch weights!"); - std::swap(Weights[0], Weights[1]); - setBranchWeights(*OrInst, Weights, /*IsExpected=*/false); - } + if (auto *OrInst = dyn_cast<Instruction>(Or)) { + if (auto *CondInst = dyn_cast<Instruction>(Cond)) { + SmallVector<uint32_t> Weights; + if (extractBranchWeights(*CondInst, Weights)) { + assert(Weights.size() == 2 && "Unexpected number of branch weights!"); + std::swap(Weights[0], Weights[1]); + setBranchWeights(*OrInst, Weights, /*IsExpected=*/false); } } } `````````` </details> https://github.com/llvm/llvm-project/pull/222409 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
