[PATCH] D63489: LCSSA PHIs should not be simplified away

Alexander via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 06:13:06 PDT 2019


alex-t created this revision.
alex-t added reviewers: rampitec, nhaehnle, hakzsam.
Herald added subscribers: hiraditya, tpr.
Herald added a project: LLVM.

We rely on LCSSA in case when the uniform value defined inside the loop with divergent exit is used outside the loop.
In some cases EarlyCSE eliminates LCSSA PHIs because of the algorithm used in SimplifyPHINode function.
It always assumes more then one incoming values and mistakenly removes LCSSA PHIs.
This causes generation of incorrect code in AMDGPU backend.


https://reviews.llvm.org/D63489

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp


Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4095,6 +4095,11 @@
 
 /// See if we can fold the given phi. If not, returns null.
 static Value *SimplifyPHINode(PHINode *PN, const SimplifyQuery &Q) {
+  // LCSSA PHIs only have one input value
+  // return nullptr here to avoid simplifying them away
+  // since they are necessary to hold out of the loop dependecies.
+  if (PN->getNumIncomingValues() < 2)
+    return nullptr;
   // If all of the PHI's incoming values are the same then replace the PHI node
   // with the common value.
   Value *CommonValue = nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63489.205316.patch
Type: text/x-patch
Size: 736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190618/9f01ef74/attachment.bin>


More information about the llvm-commits mailing list