[InstCombine] Fix inbounds preservation when swapping GEPs (PR44206)
authorNikita Popov <npopov@redhat.com>
Mon, 30 May 2022 15:09:40 +0000 (17:09 +0200)
committerNikita Popov <npopov@redhat.com>
Tue, 31 May 2022 13:45:02 +0000 (15:45 +0200)
commit36cbdaa163bd4250923eff0812f0e84ca129347e
tree0c5f8c4d54e74c89da2504f7c1436c70972e16c8
parent858e6273d938cc4d08ee053ddff3fe7b19eb302a
[InstCombine] Fix inbounds preservation when swapping GEPs (PR44206)

When reassociating GEPs, we can only keep inbounds if both original
GEPs were inbounds, and their offsets have the same sign. For the
sake of simplicity, I only handle the case where both offsets are
non-negative here.

It would probably be fine to just not preserve inbounds at all here,
but as I don't see a compile-time impact for adding the
isKnownNonNegative() calls I went with this more conservative
approach.

Fixes https://github.com/llvm/llvm-project/issues/44206.

Differential Revision: https://reviews.llvm.org/D126687
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/gep-combine-loop-invariant.ll
llvm/test/Transforms/LoopVectorize/ARM/mve-reductions.ll
llvm/test/Transforms/LoopVectorize/X86/x86-interleaved-accesses-masked-group.ll
llvm/test/Transforms/LoopVectorize/X86/x86-interleaved-store-accesses-with-gaps.ll
llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll
llvm/test/Transforms/LoopVectorize/interleaved-accesses.ll