mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-29 06:30:39 +00:00
LoopVectorizer: No need to generate pointer disambiguation checks between readonly pointers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180570 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4b55815303
commit
975b1ddf60
@ -419,7 +419,7 @@ public:
|
||||
}
|
||||
|
||||
/// Insert a pointer and calculate the start and end SCEVs.
|
||||
void insert(ScalarEvolution *SE, Loop *Lp, Value *Ptr);
|
||||
void insert(ScalarEvolution *SE, Loop *Lp, Value *Ptr, bool WritePtr);
|
||||
|
||||
/// This flag indicates if we need to add the runtime check.
|
||||
bool Need;
|
||||
@ -429,6 +429,8 @@ public:
|
||||
SmallVector<const SCEV*, 2> Starts;
|
||||
/// Holds the pointer value at the end of the loop.
|
||||
SmallVector<const SCEV*, 2> Ends;
|
||||
/// Holds the information if this pointer is used for writing to memory.
|
||||
SmallVector<bool, 2> IsWritePtr;
|
||||
};
|
||||
|
||||
/// A POD for saving information about induction variables.
|
||||
@ -787,7 +789,8 @@ struct LoopVectorize : public LoopPass {
|
||||
|
||||
void
|
||||
LoopVectorizationLegality::RuntimePointerCheck::insert(ScalarEvolution *SE,
|
||||
Loop *Lp, Value *Ptr) {
|
||||
Loop *Lp, Value *Ptr,
|
||||
bool WritePtr) {
|
||||
const SCEV *Sc = SE->getSCEV(Ptr);
|
||||
const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Sc);
|
||||
assert(AR && "Invalid addrec expression");
|
||||
@ -796,6 +799,7 @@ LoopVectorizationLegality::RuntimePointerCheck::insert(ScalarEvolution *SE,
|
||||
Pointers.push_back(Ptr);
|
||||
Starts.push_back(AR->getStart());
|
||||
Ends.push_back(ScEnd);
|
||||
IsWritePtr.push_back(WritePtr);
|
||||
}
|
||||
|
||||
Value *InnerLoopVectorizer::getBroadcastInstrs(Value *V) {
|
||||
@ -1166,6 +1170,10 @@ InnerLoopVectorizer::addRuntimeCheck(LoopVectorizationLegality *Legal,
|
||||
|
||||
for (unsigned i = 0; i < NumPointers; ++i) {
|
||||
for (unsigned j = i+1; j < NumPointers; ++j) {
|
||||
// No need to check if two readonly pointers intersect.
|
||||
if (!PtrRtCheck->IsWritePtr[i] && !PtrRtCheck->IsWritePtr[j])
|
||||
continue;
|
||||
|
||||
Value *Start0 = ChkBuilder.CreateBitCast(Starts[i], PtrArithTy, "bc");
|
||||
Value *Start1 = ChkBuilder.CreateBitCast(Starts[j], PtrArithTy, "bc");
|
||||
Value *End0 = ChkBuilder.CreateBitCast(Ends[i], PtrArithTy, "bc");
|
||||
@ -2678,7 +2686,7 @@ bool LoopVectorizationLegality::canVectorizeMemory() {
|
||||
for (MI = ReadWrites.begin(), ME = ReadWrites.end(); MI != ME; ++MI) {
|
||||
Value *V = (*MI).first;
|
||||
if (hasComputableBounds(V)) {
|
||||
PtrRtCheck.insert(SE, TheLoop, V);
|
||||
PtrRtCheck.insert(SE, TheLoop, V, true);
|
||||
DEBUG(dbgs() << "LV: Found a runtime check ptr:" << *V <<"\n");
|
||||
} else {
|
||||
CanDoRT = false;
|
||||
@ -2688,7 +2696,7 @@ bool LoopVectorizationLegality::canVectorizeMemory() {
|
||||
for (MI = Reads.begin(), ME = Reads.end(); MI != ME; ++MI) {
|
||||
Value *V = (*MI).first;
|
||||
if (hasComputableBounds(V)) {
|
||||
PtrRtCheck.insert(SE, TheLoop, V);
|
||||
PtrRtCheck.insert(SE, TheLoop, V, false);
|
||||
DEBUG(dbgs() << "LV: Found a runtime check ptr:" << *V <<"\n");
|
||||
} else {
|
||||
CanDoRT = false;
|
||||
|
36
test/Transforms/LoopVectorize/runtime-check-readonly.ll
Normal file
36
test/Transforms/LoopVectorize/runtime-check-readonly.ll
Normal file
@ -0,0 +1,36 @@
|
||||
; RUN: opt < %s -loop-vectorize -force-vector-unroll=1 -force-vector-width=4 -dce -instcombine -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-apple-macosx10.8.0"
|
||||
|
||||
;CHECK: add_ints
|
||||
;CHECK: br
|
||||
;CHECK: getelementptr
|
||||
;CHECK-NEXT: getelementptr
|
||||
;CHECK-NEXT: icmp uge
|
||||
;CHECK-NEXT: icmp uge
|
||||
;CHECK-NEXT: icmp uge
|
||||
;CHECK-NEXT: icmp uge
|
||||
;CHECK-NEXT: and
|
||||
;CHECK: ret
|
||||
define void @add_ints(i32* nocapture %A, i32* nocapture %B, i32* nocapture %C) {
|
||||
entry:
|
||||
br label %for.body
|
||||
|
||||
for.body:
|
||||
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
|
||||
%arrayidx = getelementptr inbounds i32* %B, i64 %indvars.iv
|
||||
%0 = load i32* %arrayidx, align 4
|
||||
%arrayidx2 = getelementptr inbounds i32* %C, i64 %indvars.iv
|
||||
%1 = load i32* %arrayidx2, align 4
|
||||
%add = add nsw i32 %1, %0
|
||||
%arrayidx4 = getelementptr inbounds i32* %A, i64 %indvars.iv
|
||||
store i32 %add, i32* %arrayidx4, align 4
|
||||
%indvars.iv.next = add i64 %indvars.iv, 1
|
||||
%lftr.wideiv = trunc i64 %indvars.iv.next to i32
|
||||
%exitcond = icmp eq i32 %lftr.wideiv, 200
|
||||
br i1 %exitcond, label %for.end, label %for.body
|
||||
|
||||
for.end:
|
||||
ret void
|
||||
}
|
Loading…
Reference in New Issue
Block a user