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 :slight_smile:

Gr.

Matthijs

argpromotion.diff (24.5 KB)