This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Canonicalize addrspacecast between different element types
ClosedPublic

Authored by jingyue on Jun 3 2014, 5:52 PM.

Details

Summary

addrspacecast X addrspace(M)* to Y addrspace(N)*
-->
bitcast X addrspace(M)* to Y addrspace(M)*
addrspacecast Y addrspace(M)* to Y addrspace(N)*

This canonicalization makes NVPTXFavorNonGenericAddrSpaces more effective, and can potentially benefit many other cases.

This patch is based on D2186 with fixes and more tests:

  • Fix an issue in D2186 that causes InstCombine to run into infinite loops
  • Add the failed test as @canonicalize_addrspacecast in test/Transforms/InstCombine/addrspacecast.ll
  • Do bitcast before addrspacecast because addrspacecasts from non-generic to generic can be folded into load/store
  • 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]

Diff Detail

Event Timeline

jingyue updated this revision to Diff 10073.Jun 3 2014, 5:52 PM
jingyue retitled this revision from to [InstCombine] Canonicalize addrspacecast between different element types.
jingyue updated this object.
jingyue edited the test plan for this revision. (Show Details)
jingyue added reviewers: arsenm, eliben, meheff.
jingyue added a subscriber: Unknown Object (MLST).
arsenm accepted this revision.Jun 3 2014, 6:48 PM
arsenm edited edge metadata.

LGTM

lib/Transforms/InstCombine/InstCombineCasts.cpp
1925–1926

I would remove the comment about a specific target pass

This revision is now accepted and ready to land.Jun 3 2014, 6:48 PM
jingyue closed this revision.Jun 6 2014, 3:01 PM

Committed in r210375