Simplify ScopDetection::isInvariant(). Essentially deny everything that
is defined within the SCoP and is not load-hoisted.
The previous understanding of "invariant" has a few holes:
- Expressions without side-effects with only invariant arguments, but
are defined withing the SCoP's region with the exception of selects
and PHIs. These should be part of the index expression derived by
ScalarEvolution and not of the base pointer.
- Function calls with that are !mayHaveSideEffects() (typically
functions with "readnone nounwind" attributes). An example is given
below.
@C = external global i32
declare float* @getNextBasePtr(float*) readnone nounwind
...
%ptr = call float* @getNextBasePtr(float* %A, float %B)
The call might return:
* %A, so %ptr aliases with it in the SCoP
* %B, so %ptr aliases with it in the SCoP
* @C, so %ptr aliases with it in the SCoP
* a new pointer everytime it is called, such as malloc()
* a pointer into the allocated block of one of the aforementioned
* any of the above, at random at each call
Hence and contrast to a comment in the base_pointer.ll regression
test, %ptr is not necessarily the same all the time. It might also
alias with anything and no AliasAnalysis can tell otherwise if the
definition is external. It is hence not suitable in the role of a
base pointer.
The practical problem with base pointers defined in SCoP statements is
that it is not available globally in the SCoP. The statement instance
must be executed first before the base pointer can be used. This is no
problem if the base pointer is transferred as a scalar value between
statements. Uses of MemoryAccess::setNewAccessRelation may add a use of
the base pointer anywhere in the array. setNewAccessRelation is used by
JSONImporter, DeLICM and D28518. Indeed, BlockGenerator currently
assumes that base pointers are available globally and generates invalid
code for new access relation (referring to the base pointer of the
original code) if not, even if the base pointer would be available in
the statement.
This could be fixed with some added complexity and restrictions. The
ExprBuilder must lookup the local BBMap and code that call
setNewAccessRelation must check whether the base pointer is available
first.
The code would still be incorrect in the presence of aliasing. There
is the switch -polly-ignore-aliasing to explicitly allow this, but
it is hardly a justification for the additional complexity. It would
still be mostly useless because in most cases either getNextBasePtr()
has external linkage in which case the readnone nounwind attributes
cannot be derived in the translation unit itself, or is defined in the
same translation unit and gets inlined.
Reviewed By: grosser
Differential Revision: https://reviews.llvm.org/D30695
llvm-svn: 297281
61 lines
2.7 KiB
LLVM
61 lines
2.7 KiB
LLVM
; RUN: opt %loadPolly -polly-detect -polly-codegen -polly-invariant-load-hoisting=true -analyze < %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.
|
|
;
|
|
; This SCoP is currently rejected because %call9 is not considered a valid
|
|
; base pointer.
|
|
;
|
|
; CHECK-NOT: Valid Region for Scop
|
|
;
|
|
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"}
|