[llvm] [InstCombinePass] InstCombine Pass do not sink selectInst Ptr (PR #174267)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 2 23:19:20 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: shunshun.ding (XJTUDing)
<details>
<summary>Changes</summary>
Because SROA cannot fully handle the select instruction, sinking the select instruction may lead to pointer escape.This approach is designed to avoid such a situation.
---
Full diff: https://github.com/llvm/llvm-project/pull/174267.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp (+6)
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index ba1865a2b5469..64d62769dc584 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -534,6 +534,10 @@ Instruction *InstCombinerImpl::foldPHIArgBinOpIntoPHI(PHINode &PN) {
Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
GetElementPtrInst *FirstInst =cast<GetElementPtrInst>(PN.getIncomingValue(0));
+ // Because SROA cannot fully handle the select instruction, sinking the select instruction may lead to pointer escape.
+ // This approach is designed to avoid such a situation.
+ if (isa<SelectInst>(FirstInst->getPointerOperand()))
+ return nullptr;
SmallVector<Value*, 16> FixedOperands(FirstInst->op_begin(),
FirstInst->op_end());
@@ -552,6 +556,8 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
// Scan to see if all operands are the same opcode, and all have one user.
for (Value *V : drop_begin(PN.incoming_values())) {
GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V);
+ if (isa<SelectInst>(GEP->getPointerOperand()))
+ return nullptr;
if (!GEP || !GEP->hasOneUser() ||
GEP->getSourceElementType() != FirstInst->getSourceElementType() ||
GEP->getNumOperands() != FirstInst->getNumOperands())
``````````
</details>
https://github.com/llvm/llvm-project/pull/174267
More information about the llvm-commits
mailing list