llvm.org GIT mirror llvm / 50192c2
Teach BasicAA about noalias function parameters. Passes all of DejaGNU and test-suite. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40624 91177308-0d34-0410-b5e6-96231b3b80d8 Christopher Lamb 12 years ago
2 changed file(s) with 44 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
1717 #include "llvm/Constants.h"
1818 #include "llvm/DerivedTypes.h"
1919 #include "llvm/Function.h"
20 #include "llvm/ParameterAttributes.h"
2021 #include "llvm/GlobalVariable.h"
2122 #include "llvm/Instructions.h"
2223 #include "llvm/Pass.h"
293294
294295 // Pointing at a discernible object?
295296 if (O1) {
297 // Check for noalias attribute
298 if (isa(O1)) {
299 const Argument *Arg = cast(O1);
300 const Function *Func = Arg->getParent();
301 const ParamAttrsList *Attr = Func->getFunctionType()->getParamAttrs();
302 if (Attr) {
303 unsigned Idx = 1;
304 for (Function::const_arg_iterator I = Func->arg_begin(),
305 E = Func->arg_end(); I != E; ++I, ++Idx) {
306 if (&(*I) == Arg &&
307 Attr->paramHasAttr(Idx, ParamAttr::NoAlias))
308 return NoAlias;
309 }
310 }
311 }
296312 if (O2) {
297313 if (isa(O1)) {
298314 // Incoming argument cannot alias locally allocated object!
306322 // If they are two different objects, we know that we have no alias...
307323 return NoAlias;
308324 }
309
325
326 // Check for noalias atrribute independently from above logic
327 if (isa(O2)) {
328 const Argument *Arg = cast(O2);
329 const Function *Func = Arg->getParent();
330 const ParamAttrsList *Attr = Func->getFunctionType()->getParamAttrs();
331 if (Attr) {
332 unsigned Idx = 1;
333 for (Function::const_arg_iterator I = Func->arg_begin(),
334 E = Func->arg_end(); I != E; ++I, ++Idx) {
335 if (&(*I) == Arg &&
336 Attr->paramHasAttr(Idx, ParamAttr::NoAlias))
337 return NoAlias;
338 }
339 }
340 }
310341 // If they are the same object, they we can look at the indexes. If they
311342 // index off of the object is the same for both pointers, they must alias.
312343 // If they are provably different, they must not alias. Otherwise, we
0 ; RUN: llvm-as %s -o - | opt -aa-eval -print-may-aliases -disable-output |& grep '1 may alias'
1 ; RUN: llvm-as %s -o - | opt -aa-eval -print-may-aliases -disable-output |& grep '5 no alias'
2 ; RUN: llvm-as %s -o - | opt -aa-eval -print-may-aliases -disable-output |& grep 'MayAlias: i32* %ptr4, i32* %ptr2'
3
4 define void @_Z3fooPiS_RiS_(i32* noalias %ptr1, i32* %ptr2, i32* noalias %ptr3, i32* %ptr4) {
5 entry:
6 store i32 0, i32* %ptr1
7 store i32 0, i32* %ptr2
8 store i32 0, i32* %ptr3
9 store i32 0, i32* %ptr4
10 ret void
11 }