[PATCH] D72048: [InstCombine] Preserve nuw on sub of geps (PR44419)
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 1 03:27:02 PST 2020
nikic marked an inline comment as done.
nikic added a comment.
I think this is still not quite right for the case where there are multiple GEP indexes. For example:
define i64 @test_inbounds_nuw_multi_index([0 x [2 x i32]]* %base, i64 %idx, i64 %idx2) {
; CHECK-LABEL: @test_inbounds_nuw_multi_index(
; CHECK-NEXT: [[P2_IDX:%.*]] = shl nuw nsw i64 [[IDX:%.*]], 3
; CHECK-NEXT: [[P2_IDX1:%.*]] = shl nuw nsw i64 [[IDX2:%.*]], 2
; CHECK-NEXT: [[P2_OFFS2:%.*]] = add i64 [[P2_IDX]], [[P2_IDX1]]
; CHECK-NEXT: ret i64 [[P2_OFFS2]]
;
%p1 = getelementptr inbounds [0 x [2 x i32]], [0 x [2 x i32]]* %base, i64 0, i64 0, i64 0
%p2 = getelementptr inbounds [0 x [2 x i32]], [0 x [2 x i32]]* %base, i64 0, i64 %idx, i64 %idx2
%i1 = ptrtoint i32* %p1 to i64
%i2 = ptrtoint i32* %p2 to i64
%d = sub nuw i64 %i2, %i1
ret i64 %d
}
Let's say %idx=-1, %idx2=4, then the overall result is `8 * %idx1 + 4 * %idx2 = 8`, which is positive, even though one of the intermediate indexes is negative and as such can't use `shl nuw`. I think in this case the `nuw` can't be on any of the instructions (including also not the `add`). Right?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72048/new/
https://reviews.llvm.org/D72048
More information about the llvm-commits
mailing list