[LLVMdev] Post-increments and pre-decrements

Evan Cheng evan.cheng at apple.com
Tue Dec 19 11:41:53 PST 2006


>
> I enabled these modes in my TargetLowering class using
> setIndexedLoadAction and setIndexedStoreAction calls. I also defined
> getPreIndexedAddressParts and getPostIndexedAddressParts. And I can  
> see
> that DAGCombiner::CombineToPostIndexedLoadStore is invoked. But this
> function never does any replacements and very seldomly invoke
> getPostIndexedAddressParts and so on, even in those situations where I
> would assume it.

Ok,

>
> For example, it does not use these modes for the code like:
> void test_postinc(int array[], int i)
> {
>   array[i] = 1;
>   array[i+1] = 1;
>   array[i+2] = 1;
>   array[i+3] = 1;
> }

See below.

>
> So, I'm wondering how good is the support for these modes in LLVM?  
> Do I
> miss something which should be implemented for my target to enable it?
> It looks like only PowerPC backend tries to make use of it, but even
> there it is not implemented completely.
>
> And, BTW, are there any good test-cases or sample code (either ll or c
> files) that is (or should be) translated by LLVM using these modes?  
> I'd
> like to get a better understanding about the situations where it can
> happen at all. For example, is the code like above a good candidate  
> for
> it or not?

Indexed load / store supports is not "done". Currently only PPC  
target makes use of it. Lots of testing and further refinement is  
needed.

Basically, the only cases where transformation will happen now is if  
the load/store address has other non-address uses. e.g.

x1 = load [base]
x2 = base + 4

As for your example, let's first example why array[i+1] = 1; array[i 
+2] = 1; does not currently triggers a transformation:

array[i+1] = 1
array[i+2] = 1
=>
tmp = array * 4
base = tmp + i
store 1, [base + 4]
store 1, [base + 8]

Unfortunately base+8 is not written as (base+4)+4 so the  
transformation does not happen. We need to add DAG combiner  
transformation to  make that happen. If you are interested in making  
that happen, we would be happen to help. :-)

The reason that array[i] = 1; array[i+1] = 1; doesn't trigger a  post- 
inc transformation is different. In theory, this should be
array[i]     = 1
array[i+1] = 1
=>
tmp = array * 4
base = array * 4 + i
store 1, [base]
store 1, [base + 4]

The first store should have been transformed into a post-inc store.

The issue is in SDNode CSE. If you take a look at pre-legalizer DAG  
dump. You will see this:

tmp = array * 4
base1 = array * 4 + i
base2 = i + array * 4
store 1, [base1]
store 2, [base2 + 4]

So the post-inc transformation does not recognize an opportunity. The  
current "fix" should be to teach SDNode CSE to understand commutative  
property to eliminate one of the add operation. Chris can say more  
about the issues related.

Hope this helps.

Evan


>
> -Roman
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list