[PATCH] Canonicalize addrspacecast between different pointer types.

Jingyue Wu jingyue at google.com
Tue Jun 3 16:25:01 PDT 2014


Matt, 

I think the root cause for this loop is at InstCombineCasts.cpp:1438. The code there considers a GEP with all zero indices as a bitcast, and merges it with CI. While this merging is fine for bitcast, it undoes the canonicalization if CI is addrspacecast. 

To fix this issue, I modified the code around there: if CI is addrspacecast and the getelementptr changes the pointer type, do not merge them. 

I uploaded my changes to http://reviews.llvm.org/differential/diff/10068/. These changes include: 
* Applied D2186
* Fixed the infinite loop issue and added the failed test to addrspacecast.ll
* As discussed offline, I put bitcast before addrspacecast instead of after because I slightly prefer this way. 
* Updated all affected tests. One affected test (@test2_addrspacecast) in memcpy-from-global.ll is actually better optimized because of this canonicalization. See how alloca %T being transformed to alloca [128 x i8]

I am unable to update this diff directly probably because it's not created by me. If my changes conceptually look good to you, I can create a separate revision for further review. 

Thanks,
Jingyue

http://reviews.llvm.org/D2186






More information about the llvm-commits mailing list