[PATCH] D31488: [SimplifyIndvar] Replace the sdiv used by IV if we can prove both of its operands are non-negative
Tobias Grosser via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 29 23:12:07 PDT 2017
grosser added a comment.
Hi Hongbin,
I am not sure what you are trying to achieve here. This kernel is already optimized by -instcombine to
define void @test(i32* %a) {
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%div = shl nsw i32 %i.01, 5
%idxprom = sext i32 %div to i64
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
store i32 %i.01, i32* %arrayidx, align 4
%inc = add nsw i32 %i.01, 1
%cmp = icmp slt i32 %i.01, 63
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body
ret void
}
So the sdiv is replaced by a lsh, taking into account the information that sdiv is working on unsigned inputs only.
If you divide by a non-power-of-two, instcombine does not change the code and leaves the sdiv in. However, if you would like to move to an sdiv even in this case this should probably be added to instcombine.
I would also be interested to learn why an 'udiv' is a better canonical form than an 'sdiv'. Is it faster to execute (non-power-of-two) udivs on FPGAs than sdivs?
Repository:
rL LLVM
https://reviews.llvm.org/D31488
More information about the llvm-commits
mailing list