llvm.org GIT mirror llvm / ef80e8a
[BasicAA] Remove special casing of memset_pattern16 in favor of generic attribute inference Most of the properties of memset_pattern16 can be now covered by the generic attributes and inferred by InferFunctionAttrs. The only exceptions are: - We don't yet have a writeonly attribute for the first argument. - We don't have an attribute for modeling the access size facts encoded in MemoryLocation.cpp. Differential Revision: http://reviews.llvm.org/D15879 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256911 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 4 years ago
4 changed file(s) with 35 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
542542 isa(MemsetType->getParamType(2)))
543543 return true;
544544 }
545
546545 return false;
547546 }
548547
581580
582581 if (F->onlyAccessesArgMemory())
583582 Min = FunctionModRefBehavior(Min & FMRB_OnlyAccessesArgumentPointees);
584
585 if (isMemsetPattern16(F, TLI))
586 Min = FMRB_OnlyAccessesArgumentPointees;
587583
588584 // Otherwise be conservative.
589585 return FunctionModRefBehavior(AAResultBase::getModRefBehavior(F) & Min);
608604 // We can bound the aliasing properties of memset_pattern16 just as we can
609605 // for memcpy/memset. This is particularly important because the
610606 // LoopIdiomRecognizer likes to turn loops into calls to memset_pattern16
611 // whenever possible.
612 if (CS.getCalledFunction() &&
613 isMemsetPattern16(CS.getCalledFunction(), TLI)) {
614 assert((ArgIdx == 0 || ArgIdx == 1) &&
615 "Invalid argument index for memset_pattern16");
616 return ArgIdx ? MRI_Ref : MRI_Mod;
617 }
618 // FIXME: Handle memset_pattern4 and memset_pattern8 also.
607 // whenever possible. Note that all but the missing writeonly attribute are
608 // handled via InferFunctionAttr.
609 if (CS.getCalledFunction() && isMemsetPattern16(CS.getCalledFunction(), TLI))
610 if (ArgIdx == 0)
611 return MRI_Mod;
619612
620613 if (CS.paramHasAttr(ArgIdx + 1, Attribute::ReadOnly))
621614 return MRI_Ref;
2121
2222 STATISTIC(NumReadNone, "Number of functions inferred as readnone");
2323 STATISTIC(NumReadOnly, "Number of functions inferred as readonly");
24 STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly");
2425 STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
2526 STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
2627 STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
4243 ++NumReadOnly;
4344 return true;
4445 }
46
47 static bool setOnlyAccessesArgMemory(Function &F) {
48 if (F.onlyAccessesArgMemory())
49 return false;
50 F.setOnlyAccessesArgMemory ();
51 ++NumArgMemOnly;
52 return true;
53 }
54
4555
4656 static bool setDoesNotThrow(Function &F) {
4757 if (F.doesNotThrow())
899909 Changed |= setDoesNotAlias(F, AttributeSet::ReturnIndex);
900910 return Changed;
901911
912 //TODO: add LibFunc entries for:
913 //case LibFunc::memset_pattern4:
914 //case LibFunc::memset_pattern8:
915 case LibFunc::memset_pattern16:
916 if (FTy->isVarArg() || FTy->getNumParams() != 3 ||
917 !isa(FTy->getParamType(0)) ||
918 !isa(FTy->getParamType(1)) ||
919 !isa(FTy->getParamType(2)))
920 return false;
921
922 Changed |= setOnlyAccessesArgMemory(F);
923 Changed |= setOnlyReadsMemory(F, 2);
924 return Changed;
925
902926 default:
903927 // FIXME: It'd be really nice to cover all the library functions we're
904928 // aware of here.
1717 ret i32 %l
1818 }
1919
20 declare void @memset_pattern16(i8*, i8*, i64)
20 declare void @memset_pattern16(i8*, i8* readonly, i64) argmemonly
2121 declare i8* @_Znwm(i64)
2222 ; CHECK: declare noalias nonnull i8* @_Znwm(i64)
2323
24 declare void @memset_pattern16(i8*, i8*, i64)
25 ; CHECK: declare void @memset_pattern16(i8*, i8*, i64)
26 ; CHECK-POSIX: declare void @memset_pattern16(i8*, i8* readonly, i64) [[G2:#[0-9]+]]
27
2428 declare i32 @gettimeofday(i8*, i8*)
2529 ; CHECK-POSIX: declare i32 @gettimeofday(i8* nocapture, i8* nocapture) [[G0:#[0-9]+]]
2630
2731 ; CHECK: attributes [[G0]] = { nounwind }
2832 ; CHECK: attributes [[G1]] = { nounwind readonly }
2933 ; CHECK-POSIX: attributes [[G0]] = { nounwind }
34 ; CHECK-POSIX: attributes [[G2]] = { argmemonly }