[InstCombine] Fix inbounds preservation when merging GEPs (PR55722)
authorNikita Popov <npopov@redhat.com>
Tue, 31 May 2022 09:51:19 +0000 (11:51 +0200)
committerNikita Popov <npopov@redhat.com>
Tue, 31 May 2022 09:54:01 +0000 (11:54 +0200)
commit872d69e5d4e251bd70c6cf5dbf1b3ea34f976aa2
tree39ef9f8dfed2db09d5267a5481652af66003650e
parentb501503ca0bc5562e5ef4eb736ab718fd29c7bc3
[InstCombine] Fix inbounds preservation when merging GEPs (PR55722)

Even if the total offset is inbounds, we might represent it by first
performing a large negative offset and then a small positive one.
With inbounds semantics as currently specified, each offset must
be inbounds individually, not just the overall offset of the GEP.

Fix this by checking that the sign of all offsets is the same.

Fixes https://github.com/llvm/llvm-project/issues/55722.
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/gep-merge-constant-indices.ll