[PATCH] D26947: [NVPTX] Structurize the NVPTX CFG.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 21 16:30:28 PST 2016


jlebar created this revision.
jlebar added a reviewer: tra.
jlebar added subscribers: andrewcorrigan, llvm-commits, hfinkel.
Herald added a subscriber: jholewinski.

This fixes the failures in PR27738, our longstanding incorrect codegen
bug.  It appears that our hypothesis that we were generating control
flow that's too complicated for ptxas to analyze correctly was right.


https://reviews.llvm.org/D26947

Files:
  llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp


Index: llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -111,6 +111,11 @@
       is64bit(is64bit),
       TLOF(make_unique<NVPTXTargetObjectFile>()),
       Subtarget(TT, CPU, FS, *this) {
+  // NVPTX does not strictly require a structured CFG.  However, without a
+  // structured CFG we can create control flow that is too complicated for ptxas
+  // to analyze, resulting in subtly incorrect generated code, e.g. PR 27738.
+  setRequiresStructuredCFG(true);
+
   if (TT.getOS() == Triple::NVCL)
     drvInterface = NVPTX::NVCL;
   else
@@ -271,6 +276,14 @@
   // but EarlyCSE can do neither of them.
   if (getOptLevel() != CodeGenOpt::None)
     addEarlyCSEOrGVNPass();
+
+  // NVPTX does not strictly require a structured CFG.  However, without a
+  // structured CFG we can emit control flow that is too complicated for ptxas
+  // to analyze, resulting in subtly incorrect generated code, e.g. PR 27738.
+  //
+  // SkipUniformRegions == true lets us emit unstructured control flow where we
+  // can prove that it is uniform across all the threads in a warp.
+  addPass(createStructurizeCFGPass(/* SkipUniformRegions = */ true));
 }
 
 bool NVPTXPassConfig::addInstSelector() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26947.78801.patch
Type: text/x-patch
Size: 1351 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161122/8c7721ad/attachment.bin>


More information about the llvm-commits mailing list