[llvm-commits] [llvm] r52217 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/extractvalue.ll
Matthijs Kooijman
matthijs at stdin.nl
Wed Jul 16 06:10:26 PDT 2008
Hi Chris,
> > visitExtractValueInst(I) {
> > op = I.getOperand(0);
> > if (isa<ConstantAggZero>(op))
> > use new zero;
> > else if (insertvalueinst) {
> > if (index is the thing inserted)
> > use inserted value
> > else
> > use new extract value inst of aggregate input
> > ...
I've implemented this suggestion, and it actually works pretty nicely. The
code is certainly a lot simpler. It's not really much less code, though a
large part of the new code is comments :-)
> A = insertvalue undef, X, 0, 0 ; { {X, _}, _}
> B = insertvalue A, Y, 0, 1 ; { {X, Y}, _}
> C = extractvalue B, 0 ; {X, Y}
>
> This can be simplified to
> A = insertvalue undef, X, 0 ; {X, _}
> C = insertvalue A, Y, 1 ; {X, Y}
>
> This is currently being done by iterating all the elements in C and looking up
> known values for each of them (or, for nested structs, also for sub structs if
> not all individual elements are known).
>
> This could probably be handled by iterating of the elements of C (only the
> first level), inserting extractvalue B, 0, i (ie, the partially
> matching indices plus the element index) and insertvalues for each of them (in
> effect rebuilding the request struct. For the above example, this would give:
>
> A = insertvalue undef, X, 0, 0 ; { {X, _}, _}
> B = insertvalue A, Y, 0, 1 ; { {X, Y}, _}
> Xp = extractvalue B, 0, 0
> D = insertvalue undef, Xp, 0
> Yp = extractvalue B, 0, 1
> C = insertvalue D, Yp, 1
>
> The inserted extractvalues can be folded in the next iteration, resulting in
> the wanted:
>
> D = insertvalue undef, X, 0 ; {X, _}
> C = insertvalue D, Y, 1 ; {X, Y}
The above is still a little complicated, and it turns out this can be easily
be done iteratively by swapping the order of insert and extract. i.e., turn
A = insertvalue undef, X, 0, 0 ; { {X, _}, _}
B = insertvalue A, Y, 0, 1 ; { {X, Y}, _}
C = extractvalue B, 0 ; {X, Y}
into
A = insertvalue undef, X, 0, 0 ; { {X, _}, _}
Z = extractvalue A, 0 ; {X, _}
C = insertvalue Z, Y, 1 ; {X, Y}
and iteratively into
Z = extractvalue undef, 0 ; {_, _}
A = insertvalue Z, X, 0 ; {X, _}
C = insertvalue A, Y, 1 ; {X, Y}
and finally into
A = insertvalue undef, X, 0 ; {X, _}
C = insertvalue A, Y, 1 ; {X, Y}
Thanks for the suggestion, it even catches some extra cases now :-)
Gr.
Matthijs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20080716/8afb89f2/attachment.sig>
More information about the llvm-commits
mailing list