[llvm] d485c1b - [LoopDataPrefetch] Fix crash when TTI doesn't set CacheLineSize

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 22:09:20 PDT 2022


Author: zhongyunde
Date: 2022-07-26T13:08:42+08:00
New Revision: d485c1b73e1331c14c45840a6fcc0133566672b9

URL: https://github.com/llvm/llvm-project/commit/d485c1b73e1331c14c45840a6fcc0133566672b9
DIFF: https://github.com/llvm/llvm-project/commit/d485c1b73e1331c14c45840a6fcc0133566672b9.diff

LOG: [LoopDataPrefetch] Fix crash when TTI doesn't set CacheLineSize

Fix https://github.com/llvm/llvm-project/issues/56681

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D130418

Added: 
    llvm/test/Transforms/LoopDataPrefetch/AArch64/pr56681.ll

Modified: 
    llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp b/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp
index fd2eaee8b47d7..013a119c5096e 100644
--- a/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp
@@ -213,10 +213,12 @@ bool LoopDataPrefetchLegacyPass::runOnFunction(Function &F) {
 bool LoopDataPrefetch::run() {
   // If PrefetchDistance is not set, don't run the pass.  This gives an
   // opportunity for targets to run this pass for selected subtargets only
-  // (whose TTI sets PrefetchDistance).
-  if (getPrefetchDistance() == 0)
+  // (whose TTI sets PrefetchDistance and CacheLineSize).
+  if (getPrefetchDistance() == 0 || TTI->getCacheLineSize() == 0) {
+    LLVM_DEBUG(dbgs() << "Please set both PrefetchDistance and CacheLineSize "
+                         "for loop data prefetch.\n");
     return false;
-  assert(TTI->getCacheLineSize() && "Cache line size is not set for target");
+  }
 
   bool MadeChange = false;
 

diff  --git a/llvm/test/Transforms/LoopDataPrefetch/AArch64/pr56681.ll b/llvm/test/Transforms/LoopDataPrefetch/AArch64/pr56681.ll
new file mode 100644
index 0000000000000..444d0afa2c454
--- /dev/null
+++ b/llvm/test/Transforms/LoopDataPrefetch/AArch64/pr56681.ll
@@ -0,0 +1,15 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt --loop-data-prefetch --prefetch-distance=3000 -debug-only=loop-data-prefetch -S < %s 2>&1 | FileCheck %s
+
+; REQUIRES: asserts
+
+; CHECK:  Please set both PrefetchDistance and CacheLineSize for loop data prefetch
+
+define void @calc() {
+; CHECK-LABEL: @calc(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    ret void
+;
+entry:
+  ret void
+}


        


More information about the llvm-commits mailing list