1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Eliminate trivial redundant loads across nocapture+readonly calls to uncaptured

pointer arguments.

llvm-svn: 185776
This commit is contained in:
Nick Lewycky 2013-07-07 10:15:16 +00:00
parent 181e3475a3
commit 7a38a8d88f
2 changed files with 28 additions and 4 deletions

View File

@ -450,6 +450,7 @@ AliasAnalysis::callCapturesBefore(const Instruction *I,
return AliasAnalysis::ModRef;
unsigned ArgNo = 0;
AliasAnalysis::ModRefResult R = AliasAnalysis::NoModRef;
for (ImmutableCallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
CI != CE; ++CI, ++ArgNo) {
// Only look at the no-capture or byval pointer arguments. If this
@ -463,12 +464,18 @@ AliasAnalysis::callCapturesBefore(const Instruction *I,
// is impossible to alias the pointer we're checking. If not, we have to
// assume that the call could touch the pointer, even though it doesn't
// escape.
if (!isNoAlias(AliasAnalysis::Location(*CI),
AliasAnalysis::Location(Object))) {
return AliasAnalysis::ModRef;
if (isNoAlias(AliasAnalysis::Location(*CI),
AliasAnalysis::Location(Object)))
continue;
if (CS.doesNotAccessMemory(ArgNo))
continue;
if (CS.onlyReadsMemory(ArgNo)) {
R = AliasAnalysis::Ref;
continue;
}
return AliasAnalysis::ModRef;
}
return AliasAnalysis::NoModRef;
return R;
}
// AliasAnalysis destructor: DO NOT move this to the header file for

View File

@ -0,0 +1,17 @@
; RUN: opt -gvn -S -o - < %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"
target triple = "x86_64-unknown-linux-gnu"
declare void @use(i8* readonly nocapture)
define i8 @test() {
%a = alloca i8
store i8 1, i8* %a
call void @use(i8* %a)
%b = load i8* %a
ret i8 %b
; CHECK: define i8 @test
; CHECK: call void @use(i8* %a)
; CHECK-NEXT: ret i8 1
}