[SelectionDAGBuilder] Set NoUnsignedWrap for inbounds gep and load/store offsets.
authorDan Gohman <dan433584@gmail.com>
Wed, 6 Jan 2016 00:43:06 +0000 (00:43 +0000)
committerDan Gohman <dan433584@gmail.com>
Wed, 6 Jan 2016 00:43:06 +0000 (00:43 +0000)
commit0fcad92ee35f13d1d7f4da235f11c684e95640b8
treed59c665d298c13b25dd054e13ba6c5a98289c8dd
parent4001009bac2e83c231d6faa14af0fc0432559c65
[SelectionDAGBuilder] Set NoUnsignedWrap for inbounds gep and load/store offsets.

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 is
specifically useful to the WebAssembly backend, since it permits stronger
constant offset folding.

Differential Revision: http://reviews.llvm.org/D15544

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256890 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
test/CodeGen/WebAssembly/offset.ll