This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAGBuilder] Set NoUnsignedWrap on ISD::ADD for inbounds gep
ClosedPublic

Authored by sunfish on Dec 15 2015, 3:23 PM.

Details

Summary

In an inbounds getelementptr, when an index produces a constant non-negative offset to add to the base, the add can be assumed to not have unsigned overflow.

This relies on the assumption that addresses can't occupy more than half the address space, which isn't possible in C because it wouldn't be possible to represent the difference between the start of the object and one-past-the-end in a ptrdiff_t.

Setting the NoUnsignedWrap flag is theoretically useful in general, and specifically useful to the WebAssembly backend, since it permits stronger constant offset folding.

Diff Detail

Repository
rL LLVM

Event Timeline

sunfish updated this revision to Diff 42917.Dec 15 2015, 3:23 PM
sunfish retitled this revision from to [SelectionDAGBuilder] Set NoUnsignedWrap on ISD::ADD for inbounds gep.
sunfish updated this object.
sunfish set the repository for this revision to rL LLVM.
sunfish added subscribers: majnemer, llvm-commits.

WebAssembly tests LGTM

majnemer accepted this revision.Jan 4 2016, 3:15 PM
majnemer edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jan 4 2016, 3:15 PM
This revision was automatically updated to reflect the committed changes.