[llvm] r247707 - [CorrelatedValuePropagation] Infer nonnull attributes

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 13:38:35 PDT 2015


Looks like Nico has already fixed the tests in 247712.  :)

-- Sanjoy

Mehdi Amini via llvm-commits wrote:
> Hi Igor,
>
> It seems that this broke some clang tests, do you have an ETA on the fix?
>
> Thanks,
>
>> Mehdi
>
>> On Sep 15, 2015, at 10:51 AM, Igor Laevsky via llvm-commits<llvm-commits at lists.llvm.org>  wrote:
>>
>> Author: igor.laevsky
>> Date: Tue Sep 15 12:51:50 2015
>> New Revision: 247707
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=247707&view=rev
>> Log:
>> [CorrelatedValuePropagation] Infer nonnull attributes
>>
>> LazuValueInfo can prove that value is nonnull based on the context information.
>> Make use of this ability to infer nonnull attributes for the call arguments.
>>
>> Differential Revision: http://reviews.llvm.org/D12836
>>
>>
>> Modified:
>>     llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
>>     llvm/trunk/test/Transforms/CorrelatedValuePropagation/non-null.ll
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp?rev=247707&r1=247706&r2=247707&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp Tue Sep 15 12:51:50 2015
>> @@ -44,6 +44,7 @@ namespace {
>>      bool processMemAccess(Instruction *I);
>>      bool processCmp(CmpInst *C);
>>      bool processSwitch(SwitchInst *SI);
>> +    bool processCallSite(CallSite CS);
>>
>>    public:
>>      static char ID;
>> @@ -309,6 +310,32 @@ bool CorrelatedValuePropagation::process
>>    return Changed;
>> }
>>
>> +/// processCallSite - Infer nonnull attributes for the arguments at the
>> +/// specified callsite.
>> +bool CorrelatedValuePropagation::processCallSite(CallSite CS) {
>> +  bool Changed = false;
>> +
>> +  unsigned ArgNo = 0;
>> +  for (Value *V : CS.args()) {
>> +    PointerType *Type = dyn_cast<PointerType>(V->getType());
>> +
>> +    if (Type&&  !CS.paramHasAttr(ArgNo + 1, Attribute::NonNull)&&
>> +        LVI->getPredicateAt(ICmpInst::ICMP_EQ, V,
>> +                            ConstantPointerNull::get(Type),
>> +                            CS.getInstruction()) == LazyValueInfo::False) {
>> +      AttributeSet AS = CS.getAttributes();
>> +      AS = AS.addAttribute(CS.getInstruction()->getContext(), ArgNo + 1,
>> +                           Attribute::NonNull);
>> +      CS.setAttributes(AS);
>> +      Changed = true;
>> +    }
>> +    ArgNo++;
>> +  }
>> +  assert(ArgNo == CS.arg_size()&&  "sanity check");
>> +
>> +  return Changed;
>> +}
>> +
>> bool CorrelatedValuePropagation::runOnFunction(Function&F) {
>>    if (skipOptnoneFunction(F))
>>      return false;
>> @@ -336,6 +363,10 @@ bool CorrelatedValuePropagation::runOnFu
>>        case Instruction::Store:
>>          BBChanged |= processMemAccess(II);
>>          break;
>> +      case Instruction::Call:
>> +      case Instruction::Invoke:
>> +        BBChanged |= processCallSite(CallSite(II));
>> +        break;
>>        }
>>      }
>>
>>
>> Modified: llvm/trunk/test/Transforms/CorrelatedValuePropagation/non-null.ll
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CorrelatedValuePropagation/non-null.ll?rev=247707&r1=247706&r2=247707&view=diff
>> ==============================================================================
>> --- llvm/trunk/test/Transforms/CorrelatedValuePropagation/non-null.ll (original)
>> +++ llvm/trunk/test/Transforms/CorrelatedValuePropagation/non-null.ll Tue Sep 15 12:51:50 2015
>> @@ -101,3 +101,42 @@ bb:
>> ; CHECK: KEEP2
>>    ret void
>> }
>> +
>> +declare void @test10_helper(i8* %arg1, i8* %arg2, i32 %non-pointer-arg)
>> +define void @test10(i8* %arg1, i8* %arg2, i32 %non-pointer-arg) {
>> +; CHECK-LABEL: @test10
>> +entry:
>> +  %is_null = icmp eq i8* %arg1, null
>> +  br i1 %is_null, label %null, label %non_null
>> +
>> +non_null:
>> +  call void @test10_helper(i8* %arg1, i8* %arg2, i32 %non-pointer-arg)
>> +  ; CHECK: call void @test10_helper(i8* nonnull %arg1, i8* %arg2, i32 %non-pointer-arg)
>> +  br label %null
>> +
>> +null:
>> +  call void @test10_helper(i8* %arg1, i8* %arg2, i32 %non-pointer-arg)
>> +  ; CHECK: call void @test10_helper(i8* %arg1, i8* %arg2, i32 %non-pointer-arg)
>> +  ret void
>> +}
>> +
>> +declare void @test11_helper(i8* %arg)
>> +define void @test11(i8* %arg1, i8** %arg2) {
>> +; CHECK-LABEL: @test11
>> +entry:
>> +  %is_null = icmp eq i8* %arg1, null
>> +  br i1 %is_null, label %null, label %non_null
>> +
>> +non_null:
>> +  br label %merge
>> +
>> +null:
>> +  %another_arg = alloca i8
>> +  br label %merge
>> +
>> +merge:
>> +  %merged_arg = phi i8* [%another_arg, %null], [%arg1, %non_null]
>> +  call void @test11_helper(i8* %merged_arg)
>> +  ; CHECK: call void @test11_helper(i8* nonnull %merged_arg)
>> +  ret void
>> +}
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list