[PATCH] D70076: [Polly][CodeGen]Fix getArrayAccessFor crashes as in bug 32534 with -polly-vectorizer=polly

bin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 11 05:38:17 PST 2019


bin.narwal created this revision.
bin.narwal added a reviewer: Meinersbur.
bin.narwal added projects: Polly, LLVM.
Herald added a reviewer: bollu.

Hi,
Not sure when the original crash information disappeared, the test suffers from crash in function
polly::ScopStmt::getArrayAccessFor now.

Root cause is VectorBlockGenerator::copyStmt iterates all instructions in basic block, however some
load instructions may be not unnecessary thus removed by simplification.  As a result, these load
instructions don't have corresponding Array.

Looking at BlockGenerator::copyBB, it only iterates instructions list of ScopStmt.  Given it must be
a block type scop in case of vectorization, I think we should do the same in VectorBlockGenerator::copyStmt.

A test is also added in the patch.  All tests pass, any comments?

Thanks,
bin


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70076

Files:
  lib/CodeGen/BlockGenerators.cpp
  test/Isl/CodeGen/gemm-vectorizer-polly-with-opt-isl.ll


Index: test/Isl/CodeGen/gemm-vectorizer-polly-with-opt-isl.ll
===================================================================
--- /dev/null
+++ test/Isl/CodeGen/gemm-vectorizer-polly-with-opt-isl.ll
@@ -0,0 +1,62 @@
+; RUN: opt %loadPolly -polly-vectorizer=polly -polly-opt-isl -polly-codegen -S < %s
+; Derived from C:\Users\Meinersbur\src\llvm\tools\polly\test\gemm.c
+; Original command: /root/build/llvm/release/bin/clang -DFP_ABSTOLERANCE=1e-5 -DNDEBUG -mllvm -polly -mllvm -polly-process-unprofitable -mllvm -polly-vectorizer=polly -O3 -fomit-frame-pointer -DNDEBUG -w -Werror=date-time -I /root/src/llvm/projects/test-suite/SingleSource/Benchmarks/Polybench/utilities -DPOLYBENCH_DUMP_ARRAYS -o CMakeFiles/gemm.dir/gemm.c.o -c /root/src/llvm/projects/test-suite/SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gemm/gemm.c
+
+; ModuleID = 'C:\Users\MEINER~1\AppData\Local\Temp\reproduce-ulbzd0e4\bugpoint-reduced-simplified.bc'
+source_filename = "bugpoint-output-6a6c7bd.bc"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: nounwind uwtable
+define void @kernel_gemm_StrictFP(i32 %ni, i32 %nj, i32 %nk, [1024 x double]* %C, [1024 x double]* %A, [1024 x double]* %B) #0 {
+entry:
+  br label %for.cond1.preheader
+
+for.cond1.preheader:                              ; preds = %for.inc26, %entry
+  %indvars.iv54 = phi i64 [ 0, %entry ], [ %indvars.iv.next55, %for.inc26 ]
+  br label %for.body3
+
+for.body3:                                        ; preds = %for.inc23, %for.cond1.preheader
+  %indvars.iv50 = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next51, %for.inc23 ]
+  %arrayidx5 = getelementptr inbounds [1024 x double], [1024 x double]* %C, i64 %indvars.iv54, i64 %indvars.iv50
+  store double undef, double* %arrayidx5, align 8, !tbaa !1
+  br label %for.body8
+
+for.body8:                                        ; preds = %for.body8, %for.body3
+  %indvars.iv = phi i64 [ 0, %for.body3 ], [ %indvars.iv.next, %for.body8 ]
+  %arrayidx12 = getelementptr inbounds [1024 x double], [1024 x double]* %A, i64 %indvars.iv54, i64 %indvars.iv
+  %0 = load double, double* %arrayidx12, align 8, !tbaa !1
+  %arrayidx17 = getelementptr inbounds [1024 x double], [1024 x double]* %B, i64 %indvars.iv, i64 %indvars.iv50
+  %1 = load double, double* %arrayidx17, align 8, !tbaa !1
+  %2 = load double, double* %arrayidx5, align 8, !tbaa !1
+  store double undef, double* %arrayidx5, align 8, !tbaa !1
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %wide.trip.count = zext i32 %nk to i64
+  %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count
+  br i1 %exitcond, label %for.body8, label %for.inc23
+
+for.inc23:                                        ; preds = %for.body8
+  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
+  %wide.trip.count52 = zext i32 %nj to i64
+  %exitcond53 = icmp ne i64 %indvars.iv.next51, %wide.trip.count52
+  br i1 %exitcond53, label %for.body3, label %for.inc26
+
+for.inc26:                                        ; preds = %for.inc23
+  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
+  %wide.trip.count56 = zext i32 %ni to i64
+  %exitcond57 = icmp ne i64 %indvars.iv.next55, %wide.trip.count56
+  br i1 %exitcond57, label %for.cond1.preheader, label %for.cond.for.end28_crit_edge
+
+for.cond.for.end28_crit_edge:                     ; preds = %for.inc26
+  ret void
+}
+
+attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.ident = !{!0}
+
+!0 = !{!"clang version 5.0.0 "}
+!1 = !{!2, !2, i64 0}
+!2 = !{!"double", !3, i64 0}
+!3 = !{!"omnipotent char", !4, i64 0}
+!4 = !{!"Simple C/C++ TBAA"}
Index: lib/CodeGen/BlockGenerators.cpp
===================================================================
--- lib/CodeGen/BlockGenerators.cpp
+++ lib/CodeGen/BlockGenerators.cpp
@@ -1391,8 +1391,8 @@
 
   generateScalarVectorLoads(Stmt, VectorBlockMap);
 
-  for (Instruction &Inst : *BB)
-    copyInstruction(Stmt, &Inst, VectorBlockMap, ScalarBlockMap, NewAccesses);
+  for (Instruction *Inst : Stmt.getInstructions())
+    copyInstruction(Stmt, Inst, VectorBlockMap, ScalarBlockMap, NewAccesses);
 
   verifyNoScalarStores(Stmt);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70076.228677.patch
Type: text/x-patch
Size: 4621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191111/9fca54ef/attachment-0001.bin>


More information about the llvm-commits mailing list