[llvm] r217344 - Add an AlignmentFromAssumptions Pass

Andrew Trick atrick at apple.com
Sun Sep 7 16:28:39 PDT 2014


> On Sep 7, 2014, at 4:16 PM, Hal Finkel <hfinkel at anl.gov> wrote:
> 
> ----- Original Message -----
>> From: "Andrew Trick" <atrick at apple.com>
>> To: "Hal Finkel" <hfinkel at anl.gov>
>> Cc: "llvm commits" <llvm-commits at cs.uiuc.edu>
>> Sent: Sunday, September 7, 2014 5:29:41 PM
>> Subject: Re: [llvm] r217344 - Add an AlignmentFromAssumptions Pass
>> 
>> On Sep 7, 2014, at 1:05 PM, Hal Finkel < hfinkel at anl.gov > wrote:
>> 
>> +// Given an expression for the (constant) alignment, AlignSCEV, and
>> an
>> +// expression for the displacement between a pointer and the aligned
>> address,
>> +// DiffSCEV, compute the alignment of the displaced pointer if it
>> can be
>> +// reduced to a constant.
>> +static unsigned getNewAlignmentDiff(const SCEV *DiffSCEV,
>> + const SCEV *AlignSCEV,
>> + ScalarEvolution *SE) {
>> + // DiffUnits = Diff % int64_t(Alignment)
>> + const SCEV *DiffAlignDiv = SE->getUDivExpr(DiffSCEV, AlignSCEV);
>> + const SCEV *DiffAlign = SE->getMulExpr(DiffAlignDiv, AlignSCEV);
>> + const SCEV *DiffUnitsSCEV = SE->getMinusSCEV(DiffAlign, DiffSCEV);
>> +
>> + DEBUG(dbgs() << "\talignment relative to " << *AlignSCEV << " is "
>> <<
>> + *DiffUnitsSCEV << " (diff: " << *DiffSCEV << ")\n");
>> +
>> + if (const SCEVConstant *ConstDUSCEV =
>> + dyn_cast<SCEVConstant>(DiffUnitsSCEV)) {
>> + int64_t DiffUnits = ConstDUSCEV->getValue()->getSExtValue();
>> 
>> 
>> Hi Hal,
>> 
>> 
>> One thing I didn’t understand after reviewing this is how
>> DIffUnitsSCEV can be constant if either DiffSCEV or AlignSCEV are
>> nonconstant. Are you ever seeing that case? If so, can you post
>> SCEVs that you’re seeing so I can understand and we can add
>> comments?
> 
> Sure, there is at least one function in the regression test that demonstrate this. Here's one (so DiffSCEV is {16,+,32}<nuw><%for.body>, and AlignSCEV is 32, so the remainder is a constant):
> 
> AFI: alignment of   %arrayidx = getelementptr inbounds i32* %a, i64 %indvars.iv relative to 32 and offset 0 using diff {16,+,32}<%for.body>
>        alignment relative to 32 is -16 (diff: {16,+,32}<nuw><%for.body>)
>        new alignment: 16

Of course, a recurrence with constant operands does it, and is quite common. Thanks.
-Andy

> 
> define i32 @joo(i32* nocapture %a) nounwind uwtable readonly {
> entry:
>  %ptrint = ptrtoint i32* %a to i64
>  %maskedptr = and i64 %ptrint, 31
>  %maskcond = icmp eq i64 %maskedptr, 0
>  tail call void @llvm.assume(i1 %maskcond)
>  br label %for.body
> 
> for.body:                                         ; preds = %entry, %for.body
>  %indvars.iv = phi i64 [ 4, %entry ], [ %indvars.iv.next, %for.body ]
>  %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ]
>  %arrayidx = getelementptr inbounds i32* %a, i64 %indvars.iv
>  %0 = load i32* %arrayidx, align 4
>  %add = add nsw i32 %0, %r.06
>  %indvars.iv.next = add i64 %indvars.iv, 8
>  %1 = trunc i64 %indvars.iv.next to i32
>  %cmp = icmp slt i32 %1, 2048
>  br i1 %cmp, label %for.body, label %for.end
> 
> for.end:                                          ; preds = %for.body
>  %add.lcssa = phi i32 [ %add, %for.body ]
>  ret i32 %add.lcssa
> 
> ; CHECK-LABEL: @joo
> ; CHECK: load i32* %arrayidx, align 16
> ; CHECK: ret i32 %add.lcssa
> }
> 
> Thanks again,
> Hal
> 
>> 
>> 
>> -Andy
> 
> -- 
> Hal Finkel
> Assistant Computational Scientist
> Leadership Computing Facility
> Argonne National Laboratory





More information about the llvm-commits mailing list