[llvm] r246240 - Fix: CFLAA -- Mark no-args returns as unknown
George Burgess IV via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 17:16:18 PDT 2015
Author: gbiv
Date: Thu Aug 27 19:16:18 2015
New Revision: 246240
URL: http://llvm.org/viewvc/llvm-project?rev=246240&view=rev
Log:
Fix: CFLAA -- Mark no-args returns as unknown
Prior to this patch, we hadn't been marking StratifiedSets with the
appropriate StratifiedAttrs when handling the result of no-args call
instructions. This caused us to report NoAlias when handed, for
example, an escaped alloca and a result from an opaque function. Now we
properly mark the return value of said functions.
Thanks again to Chandler, Richard, and Nick for pinging me about this.
Differential review: http://reviews.llvm.org/D12408
Added:
llvm/trunk/test/Analysis/CFLAliasAnalysis/opaque-call-alias.ll
Modified:
llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp
Modified: llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp?rev=246240&r1=246239&r2=246240&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp Thu Aug 27 19:16:18 2015
@@ -398,6 +398,8 @@ public:
}
template <typename InstT> void visitCallLikeInst(InstT &Inst) {
+ // TODO: Add support for noalias args/all the other fun function attributes
+ // that we can tack on.
SmallVector<Function *, 4> Targets;
if (getPossibleTargets(&Inst, Targets)) {
if (tryInterproceduralAnalysis(Targets, &Inst, Inst.arg_operands()))
@@ -406,8 +408,16 @@ public:
Output.clear();
}
+ // Because the function is opaque, we need to note that anything
+ // could have happened to the arguments, and that the result could alias
+ // just about anything, too.
+ // The goal of the loop is in part to unify many Values into one set, so we
+ // don't care if the function is void there.
for (Value *V : Inst.arg_operands())
Output.push_back(Edge(&Inst, V, EdgeType::Assign, AttrAll));
+ if (Inst.getNumArgOperands() == 0 &&
+ Inst.getType() != Type::getVoidTy(Inst.getContext()))
+ Output.push_back(Edge(&Inst, &Inst, EdgeType::Assign, AttrAll));
}
void visitCallInst(CallInst &Inst) { visitCallLikeInst(Inst); }
Added: llvm/trunk/test/Analysis/CFLAliasAnalysis/opaque-call-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CFLAliasAnalysis/opaque-call-alias.ll?rev=246240&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CFLAliasAnalysis/opaque-call-alias.ll (added)
+++ llvm/trunk/test/Analysis/CFLAliasAnalysis/opaque-call-alias.ll Thu Aug 27 19:16:18 2015
@@ -0,0 +1,20 @@
+; We previously had a case where we would put results from a no-args call in
+; its own stratified set. This would make cases like the one in @test say that
+; nothing (except %Escapes and %Arg) can alias
+
+; RUN: opt < %s -cfl-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
+
+; CHECK: Function: test
+; CHECK: MayAlias: i8* %Arg, i8* %Escapes
+; CHECK: MayAlias: i8* %Arg, i8* %Retrieved
+; CHECK: MayAlias: i8* %Escapes, i8* %Retrieved
+define void @test(i8* %Arg) {
+ %Noalias = alloca i8
+ %Escapes = alloca i8
+ call void @set_thepointer(i8* %Escapes)
+ %Retrieved = call i8* @get_thepointer()
+ ret void
+}
+
+declare void @set_thepointer(i8* %P)
+declare i8* @get_thepointer()
More information about the llvm-commits
mailing list