diff options
| author | Snehasish Kumar <snehasishk@google.com> | 2026-02-03 05:18:42 +0000 |
|---|---|---|
| committer | Snehasish Kumar <snehasishk@google.com> | 2026-02-10 22:50:09 +0000 |
| commit | 7cda2dafd4113326b50695a6723a9238d5c1a3ea (patch) | |
| tree | 6c264ffd2ba31bf01d731ce3fd513c0cc82e8a37 | |
| parent | 5aa88ac52e2867fe98e3e55d8a14465ab54b2633 (diff) | |
| download | llvm-users/snehasish/fix-select-factorize-prof.tar.gz llvm-users/snehasish/fix-select-factorize-prof.tar.bz2 llvm-users/snehasish/fix-select-factorize-prof.zip | |
InstCombine: Propagate profile metadata in select factorization foldingusers/snehasish/fix-select-factorize-prof
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 24 | ||||
| -rw-r--r-- | llvm/utils/profcheck-xfail.txt | 1 |
2 files changed, 12 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 1f2b7154ba42..0df463221558 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -4919,25 +4919,25 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { 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 e3c4a8dfcbab..2b91d7f8a196 100644 --- a/llvm/utils/profcheck-xfail.txt +++ b/llvm/utils/profcheck-xfail.txt @@ -244,7 +244,6 @@ Transforms/InstCombine/or-fcmp.ll 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 |
