[llvm-commits] [llvm] r52217 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/extractvalue.ll

Matthijs Kooijman matthijs at stdin.nl
Tue Jun 24 01:33:05 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
> ...
> }
That actually sounds like a sane idea. In the existing implementation
however, there is also some handling of some more complex cases. I'll just
give examples, to see if the new approach handles them as well.

	A = insertvalue undef, X, 0 ; {X, _}
	B = insertvalue undef, A, 0 ; { {X, _}, _}
	C = extractvalue B, 0, 0 ; X

Trivially implementing your above suggestions would turn this into
	C = extractvalue undef, 0, 0
since the indices of the extractvalue (0, 0) don't match those of the insert
(0). So, we will need to support partial matches as well, which should be
translated to:
	C = extractvalue A, 0;
i.e., use the partially matching insertvalue's inserted value and remove the
partially matching indices from the extractvalue.

	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 A, Y, 1 ; {X, Y}

So, it seems that this approach is indeed simpler and would work in all cases
I can think of just now. Any other thoughts?

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/20080624/82ee5a5f/attachment.sig>


More information about the llvm-commits mailing list