[PATCH] D125202: [Polly] Disable matmul pattern-match + -polly-parallel

Siddharth Bhat via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 8 20:42:09 PDT 2022


bollu created this revision.
bollu added reviewers: Meinersbur, grosser.
bollu added a project: Polly.
Herald added a subscriber: arjunp.
Herald added a project: All.
bollu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The two interact poorly and lead to miscompiles
(see: https://groups.google.com/g/polly-dev/c/gYyPbg5yWOs/m/dPyhM_w-AwAJ).
We disable the matrix multiplication pattern match if `polly-parallel`
is supplied.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125202

Files:
  polly/include/polly/CodeGen/IslAst.h
  polly/lib/CodeGen/IslAst.cpp
  polly/lib/Transform/MatmulOptimizer.cpp


Index: polly/lib/Transform/MatmulOptimizer.cpp
===================================================================
--- polly/lib/Transform/MatmulOptimizer.cpp
+++ polly/lib/Transform/MatmulOptimizer.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "polly/MatmulOptimizer.h"
+#include "polly/CodeGen/IslAst.h"
 #include "polly/DependenceInfo.h"
 #include "polly/Options.h"
 #include "polly/ScheduleTreeTransform.h"
@@ -1031,7 +1032,10 @@
                                 const llvm::TargetTransformInfo *TTI,
                                 const Dependences *D) {
   MatMulInfoTy MMI;
-  if (isMatrMultPattern(Node, D, MMI)) {
+  // FIXME: Polly's parallel scheduler and the matrix multiplication
+  // pattern match produce invalid code. Disable the matrix pattern
+  // entirely if `-polly-parallel` is used.
+  if (!PollyParallel && isMatrMultPattern(Node, D, MMI)) {
     LLVM_DEBUG(dbgs() << "The matrix multiplication pattern was detected\n");
     return optimizeMatMulPattern(Node, TTI, MMI);
   }
Index: polly/lib/CodeGen/IslAst.cpp
===================================================================
--- polly/lib/CodeGen/IslAst.cpp
+++ polly/lib/CodeGen/IslAst.cpp
@@ -59,10 +59,12 @@
 
 using IslAstUserPayload = IslAstInfo::IslAstUserPayload;
 
-static cl::opt<bool>
-    PollyParallel("polly-parallel",
-                  cl::desc("Generate thread parallel code (isl codegen only)"),
-                  cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
+bool PollyParallel;
+static cl::opt<bool, true>
+    XPollyParallel("polly-parallel",
+                   cl::desc("Generate thread parallel code (isl codegen only)"),
+                   cl::ZeroOrMore, cl::cat(PollyCategory),
+                   cl::location(PollyParallel), cl::init(false));
 
 static cl::opt<bool> PrintAccesses("polly-ast-print-accesses",
                                    cl::desc("Print memory access functions"),
Index: polly/include/polly/CodeGen/IslAst.h
===================================================================
--- polly/include/polly/CodeGen/IslAst.h
+++ polly/include/polly/CodeGen/IslAst.h
@@ -26,6 +26,9 @@
 #include "llvm/IR/PassManager.h"
 #include "isl/ctx.h"
 
+/// Command line switch whether to model read-only accesses.
+extern bool PollyParallel;
+
 namespace polly {
 using llvm::SmallPtrSet;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125202.427972.patch
Type: text/x-patch
Size: 2391 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220509/bcd267ae/attachment.bin>


More information about the llvm-commits mailing list