Matthijs Kooijman
2008-Jul-10 10:41 UTC
[LLVMdev] Argpromotion improvements (and fix for PR 2498)
Hi All, in the last few days I've been working on a fix for PR2498. Currently ArgumentPromotion is a bit overzealous when promoting arguments: If any load of a pointer argument happens in the entry block (even a partial load for a struct pointer), it assumes that all loads in the function can be promoted to the caller (and thus executed uncondtionally). This is clearly wrong, as PR2498 illustrates (if you get a char *s passed in, and you unconditionally load s[0], you can't assume that loading s[100000] is also safe). The attached patch fixes this by tracking safety of loads per set of indices, instead of just one bool for all loads. In this way, only loads that are really safe will be promoted. If there are any non-safe loads left, nothing will be promoted at all. The attached patch also includes a testcase. It passes the both the DejaGNU tests and the test suite. Fixing this required some restructuring of the Argpromotion pass. In particular, indices are no longer tracked as Value*, but as unsigned, since that resolves the differences in integer constants of different type (since GEP allows both i64 and i32). Also, the way IsSafeToPromoteArgument works is rather different now. Because of these changes, I would like the patch to be reviewed before committing :-) Gr. Matthijs -------------- next part -------------- A non-text attachment was scrubbed... Name: argpromotion.diff Type: text/x-diff Size: 24517 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080710/f7fa3f40/attachment.diff> -------------- 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-dev/attachments/20080710/f7fa3f40/attachment.sig>