From 37ade2b8015d86e73c62ab48a2ce5f0ce10de708 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sun, 7 Jul 2013 10:15:16 +0000 Subject: [PATCH] Eliminate trivial redundant loads across nocapture+readonly calls to uncaptured pointer arguments. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185776 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/AliasAnalysis.cpp | 15 +++++++++++---- test/Transforms/GVN/readattrs.ll | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 test/Transforms/GVN/readattrs.ll diff --git a/lib/Analysis/AliasAnalysis.cpp b/lib/Analysis/AliasAnalysis.cpp index 3454ce0be2b..054930c0e19 100644 --- a/lib/Analysis/AliasAnalysis.cpp +++ b/lib/Analysis/AliasAnalysis.cpp @@ -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 diff --git a/test/Transforms/GVN/readattrs.ll b/test/Transforms/GVN/readattrs.ll new file mode 100644 index 00000000000..7baee998613 --- /dev/null +++ b/test/Transforms/GVN/readattrs.ll @@ -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 +} -- 2.34.1