InstCombine: Propagate profile metadata in select factorization folding
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 1f2b715..0df4632 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -4919,25 +4919,25 @@ Value *NewTrueVal = IsAnd ? V : TrueVal; Value *NewFalseVal = IsAnd ? FalseVal : V; - // If the True and False values don't change, then preserve the branch - // 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) { - MDFrom = &SI; + if (!ProfcheckDisableMetadataFixes) { + if (NewTrueVal == TrueVal && NewFalseVal == FalseVal) + return SelectInst::Create(A, NewTrueVal, NewFalseVal, "", nullptr, + &SI); + return createSelectInstWithUnknownProfile(A, NewTrueVal, NewFalseVal); } - return SelectInst::Create(A, NewTrueVal, NewFalseVal, "", nullptr, - MDFrom); + return SelectInst::Create(A, NewTrueVal, NewFalseVal); } // Is (select B, T, F) a SPF? if (CondVal->hasOneUse() && SelType->isIntOrIntVectorTy()) { if (ICmpInst *Cmp = dyn_cast<ICmpInst>(B)) if (Value *V = canonicalizeSPF(SI, *Cmp, *this)) { - Instruction *MDFrom = ProfcheckDisableMetadataFixes ? nullptr : &SI; - return SelectInst::Create(A, IsAnd ? V : TrueVal, - IsAnd ? FalseVal : V, "", nullptr, MDFrom); + Value *NewTrueVal = IsAnd ? V : TrueVal; + Value *NewFalseVal = IsAnd ? FalseVal : V; + if (!ProfcheckDisableMetadataFixes) + return createSelectInstWithUnknownProfile(A, NewTrueVal, + NewFalseVal); + return SelectInst::Create(A, NewTrueVal, NewFalseVal); } }
diff --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt index e3c4a8d..2b91d7f 100644 --- a/llvm/utils/profcheck-xfail.txt +++ b/llvm/utils/profcheck-xfail.txt
@@ -244,7 +244,6 @@ Transforms/InstCombine/pow-1.ll Transforms/InstCombine/pow-3.ll Transforms/InstCombine/pow-sqrt.ll -Transforms/InstCombine/select-factorize.ll Transforms/InstCombine/select-min-max.ll Transforms/InstCombine/select-of-symmetric-selects.ll Transforms/InstCombine/select-select.ll