[LLVMdev] Question about shouldMergeGEPs in InstructionCombining
Mark Heffernan
meheff at google.com
Thu Mar 12 13:14:43 PDT 2015
Coincidentally, I just ran into this same issue on some of our benchmarks
for the NVPTX backend. You have something like this before instcombine:
%tmp = getelementptr inbounds i32, i32* %input, i64 %offset
loop:
%loop_variant = ...
%ptr = getelementptr inbounds i32, i32* %tmp, i64 %loop_variant
Which gets transformed to:
loop:
%loop_variant = ...
%sum = add nsw i64 %loop_variant, %offset
%ptr = getelementptr inbounds i32, i32* %input, i64 %sum
The merge essentially reassociates the loop-variant term (%loop_variant)
and loop-invariant terms (%input and %offset) in such a way that LICM can't
remove it.
One idea is to only perform this style of gep merge if at least one of the
following conditions is true:
(1) both index terms in the GEP are constant. In this case no new add
instruction is created, instead the constants are folded.
(2) the GEPs are in the same BB.
(3) LoopInfo is available, and we know we're not creating a new instruction
in a (deeper) loop.
What do you think?
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150312/47af6f01/attachment.html>
More information about the llvm-dev
mailing list