[polly] r250663 - [FIX] Do not hoist invariant pointers with non-loaded base ptr in SCoP

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 18 12:49:25 PDT 2015


Author: jdoerfert
Date: Sun Oct 18 14:49:25 2015
New Revision: 250663

URL: http://llvm.org/viewvc/llvm-project?rev=250663&view=rev
Log:
[FIX] Do not hoist invariant pointers with non-loaded base ptr in SCoP

  If the base pointer of a load is invariant and defined in the SCoP but
  not loaded we cannot hoist the load as we would not hoist the base
  pointer definition.

  This fixes bug 25237.


Added:
    polly/trunk/test/Isl/CodeGen/invariant_verify_function_failed.ll
Modified:
    polly/trunk/lib/Analysis/ScopInfo.cpp

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=250663&r1=250662&r2=250663&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Sun Oct 18 14:49:25 2015
@@ -2545,6 +2545,19 @@ void Scop::hoistInvariantLoads() {
       if (MA->isImplicit() || MA->isWrite() || !MA->isAffine())
         continue;
 
+      // Skip accesses that have an invariant base pointer which is defined but
+      // not loaded inside the SCoP. This can happened e.g., if a readnone call
+      // returns a pointer that is used as a base address. However, as we want
+      // to hoist indirect pointers, we allow the base pointer to be defined in
+      // the region if it is also a memory access. Hence, if the ScopArrayInfo
+      // object has a base pointer origin we know the base pointer is loaded and
+      // that it is invariant, thus it will be hoisted too.
+      const ScopArrayInfo *SAI = MA->getScopArrayInfo();
+      if (!SAI->getBasePtrOriginSAI())
+        if (auto *BasePtrInst = dyn_cast<Instruction>(SAI->getBasePtr()))
+          if (R.contains(BasePtrInst))
+            continue;
+
       // Skip accesses in non-affine subregions as they might not be executed
       // under the same condition as the entry of the non-affine subregion.
       if (BB != MA->getAccessInstruction()->getParent())

Added: polly/trunk/test/Isl/CodeGen/invariant_verify_function_failed.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/invariant_verify_function_failed.ll?rev=250663&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/invariant_verify_function_failed.ll (added)
+++ polly/trunk/test/Isl/CodeGen/invariant_verify_function_failed.ll Sun Oct 18 14:49:25 2015
@@ -0,0 +1,57 @@
+; RUN: opt %loadPolly -S -polly-codegen %s | FileCheck %s
+;
+; This crashed at some point as the pointer returned by the call
+; to @__errno_location is invariant and defined in the SCoP but not
+; loaded. Therefore it is not hoisted and consequently not available
+; at the beginning of the SCoP where we would need it if we would try
+; to hoist %tmp. We don't try to hoist %tmp anymore but this test still
+; checks that this passes to code generation and produces valid code.
+;
+; CHECK: polly.start
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+; Function Attrs: nounwind uwtable
+define void @fileblobSetFilename() #0 {
+entry:
+  br i1 undef, label %if.end, label %cleanup
+
+if.end:                                           ; preds = %entry
+  br i1 undef, label %land.lhs.true, label %if.end.18
+
+land.lhs.true:                                    ; preds = %if.end
+  %call9 = tail call i32* @__errno_location() #2
+  %tmp = load i32, i32* %call9, align 4, !tbaa !1
+  br i1 false, label %if.then.12, label %if.end.18
+
+if.then.12:                                       ; preds = %land.lhs.true
+  br label %if.end.18
+
+if.end.18:                                        ; preds = %if.then.12, %land.lhs.true, %if.end
+  %fd.0 = phi i32 [ undef, %if.then.12 ], [ undef, %land.lhs.true ], [ undef, %if.end ]
+  br i1 undef, label %if.then.21, label %if.end.27
+
+if.then.21:                                       ; preds = %if.end.18
+  unreachable
+
+if.end.27:                                        ; preds = %if.end.18
+  br label %cleanup
+
+cleanup:                                          ; preds = %if.end.27, %entry
+  ret void
+}
+
+; Function Attrs: nounwind readnone
+declare i32* @__errno_location() #1
+
+attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { nounwind readnone }
+
+!llvm.ident = !{!0}
+
+!0 = !{!"clang version 3.8.0 (trunk 250010) (llvm/trunk 250018)"}
+!1 = !{!2, !2, i64 0}
+!2 = !{!"int", !3, i64 0}
+!3 = !{!"omnipotent char", !4, i64 0}
+!4 = !{!"Simple C/C++ TBAA"}




More information about the llvm-commits mailing list