[llvm-branch-commits] [llvm] [InstCombine][AMDGPU] Fold select of intrinsics differing in one operand (PR #227737)
Harrison Hao via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Oct 14 02:58:13 PDT 2026
================
@@ -503,6 +503,48 @@ Instruction *InstCombinerImpl::foldSelectOpOp(SelectInst &SI, Instruction *TI,
return nullptr;
}
+/// select C, f(..., X, ...), f(..., Y, ...) --> f(..., select C, X, Y, ...)
+static Instruction *
+foldSelectIntoIntrinsicArg(SelectInst &SI, IntrinsicInst *TII,
+ IntrinsicInst *FII,
+ InstCombiner::BuilderTy &Builder) {
+ if (TII->getCalledFunction() != FII->getCalledFunction())
+ return nullptr;
+
+ std::optional<unsigned> DiffArgNo;
+ for (unsigned I = 0, E = TII->arg_size(); I != E; ++I) {
+ if (TII->getArgOperand(I) == FII->getArgOperand(I))
+ continue;
+ if (DiffArgNo)
+ return nullptr;
+ DiffArgNo = I;
+ }
+ if (!DiffArgNo)
+ return nullptr;
+
+ // A select cannot feed a parameter that requires an immediate.
+ if (TII->paramHasAttr(*DiffArgNo, Attribute::ImmArg))
----------------
harrisonGPU wrote:
Updated.
https://github.com/llvm/llvm-project/pull/227737
More information about the llvm-branch-commits
mailing list