[llvm] [AMDGPU] Do not use original PHIs in coercion chains (PR #98063)
Jeffrey Byrnes via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 10:23:31 PDT 2024
================
@@ -365,13 +365,26 @@ bool LiveRegOptimizer::optimizeLiveType(
else
MissingIncVal = true;
}
- Instruction *DeadInst = Phi;
+
if (MissingIncVal) {
- DeadInst = cast<Instruction>(ValMap[Phi]);
- // Do not use the dead phi
- ValMap[Phi] = Phi;
- }
- DeadInsts.emplace_back(DeadInst);
+ Value *DeadVal = ValMap[Phi];
+ // The coercion chain of the PHI is broken. Delete the Phi
+ // from the ValMap and any connected / user Phis.
----------------
jrbyrnes wrote:
The issue is when one PHINode uses another -- in this case, we don't use the bitcast + replace use approach.
In this case, we first create empty new typed PHI nodes. Then, we tie together the new PHI nodes with their incoming values. However, the tieing process can fail if we are missing an incoming value. Then the new typed PHI node becomes trash. This is a problem if another PHI node uses it. Currently, we replace the first PHI node with its original type in the ValMap, meaning the second PHI node will have an incompatible type.
The iteration order is non deterministic, so we may have processed the second PHI node before processing the first PHI node. In this scenario, the second PHI node will use the new-typed / trash version of first PHI node. So, when if we are unable to supply all incoming values for a PHI node, we must traverse the users and mark them as dead / unusable. Since the PHINode chain is removed from the ValMap, they won't be propagated to other users.
https://github.com/llvm/llvm-project/pull/98063
More information about the llvm-commits
mailing list