CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
260 lines
10 KiB
LLVM
260 lines
10 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
|
|
|
|
; Constant-indexed GEP instructions in a chain of GEP instructions should be
|
|
; swapped to the end whenever such transformation is valid. This allows them to
|
|
; be merged.
|
|
|
|
declare void @use(i1)
|
|
|
|
|
|
; The constant-indexed GEP instruction should be swapped to the end, even
|
|
; without merging.
|
|
; result = (((ptr) p + a) + b) + 1
|
|
define ptr @basic(ptr %p, i64 %a, i64 %b) {
|
|
; CHECK-LABEL: @basic(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[P:%.*]], i64 4
|
|
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [4 x i8], ptr [[TMP1]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [4 x i8], ptr [[TMP2]], i64 [[B:%.*]]
|
|
; CHECK-NEXT: ret ptr [[TMP3]]
|
|
;
|
|
%1 = getelementptr inbounds i32, ptr %p, i64 1
|
|
%2 = getelementptr inbounds i32, ptr %1, i64 %a
|
|
%3 = getelementptr inbounds i32, ptr %2, i64 %b
|
|
ret ptr %3
|
|
}
|
|
|
|
; GEP with the last index being a constant should also be swapped.
|
|
define ptr @partialConstant1(ptr %p, i64 %a, i64 %b) {
|
|
; CHECK-LABEL: @partialConstant1(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [4 x i8], ptr [[P:%.*]], i64 [[B:%.*]]
|
|
; CHECK-NEXT: ret ptr [[TMP1]]
|
|
;
|
|
%1 = getelementptr inbounds [4 x i32], ptr %p, i64 %a, i64 1
|
|
%2 = getelementptr inbounds i32, ptr %p, i64 %b
|
|
ret ptr %2
|
|
}
|
|
|
|
; Negative test. GEP should not be swapped if the last index is not a constant.
|
|
define ptr @partialConstant2(ptr %p, i64 %a, i64 %b) {
|
|
; CHECK-LABEL: @partialConstant2(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [4 x i8], ptr [[P:%.*]], i64 [[B:%.*]]
|
|
; CHECK-NEXT: ret ptr [[TMP1]]
|
|
;
|
|
%1 = getelementptr inbounds [4 x i32], ptr %p, i64 1, i64 %a
|
|
%2 = getelementptr inbounds i32, ptr %p, i64 %b
|
|
ret ptr %2
|
|
}
|
|
|
|
; Constant-indexed GEP are merged after swawpping.
|
|
; result = ((ptr) p + a) + 3
|
|
define ptr @merge(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr i8, ptr [[TMP1]], i64 12
|
|
; CHECK-NEXT: ret ptr [[TMP2]]
|
|
;
|
|
%1 = getelementptr inbounds i32, ptr %p, i64 1
|
|
%2 = getelementptr inbounds i32, ptr %1, i64 %a
|
|
%3 = getelementptr inbounds i32, ptr %2, i64 2
|
|
ret ptr %3
|
|
}
|
|
|
|
; Multiple constant-indexed GEP. Note that the first two cannot be merged at
|
|
; first, but after the second and third are merged, the result can be merged
|
|
; with the first one on the next pass.
|
|
; result = (ptr) ((ptr) ((ptr) ptr + a) + (a * b)) + 9
|
|
define ptr @nested(ptr %p, i64 %a, i64 %b) {
|
|
; CHECK-LABEL: @nested(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[TMP2:%.*]] = mul i64 [[A]], [[B:%.*]]
|
|
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr [2 x i8], ptr [[TMP1]], i64 [[TMP2]]
|
|
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr i8, ptr [[TMP3]], i64 160
|
|
; CHECK-NEXT: ret ptr [[TMP4]]
|
|
;
|
|
%1 = getelementptr inbounds <3 x i32>, ptr %p, i64 1
|
|
%2 = getelementptr inbounds i8, ptr %1, i64 %a
|
|
%3 = mul i64 %a, %b
|
|
%4 = getelementptr inbounds <5 x i32>, ptr %2, i64 4
|
|
%5 = getelementptr inbounds i16, ptr %4, i64 %3
|
|
%6 = getelementptr inbounds <4 x i32>, ptr %5, i64 1
|
|
ret ptr %6
|
|
}
|
|
|
|
; It is valid to swap if the source operand of the first GEP has multiple uses.
|
|
define ptr @multipleUses1(ptr %p) {
|
|
; CHECK-LABEL: @multipleUses1(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[P:%.*]], i64 4
|
|
; CHECK-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[P]] to i64
|
|
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [4 x i8], ptr [[TMP1]], i64 [[TMP2]]
|
|
; CHECK-NEXT: ret ptr [[TMP3]]
|
|
;
|
|
%1 = getelementptr inbounds i32, ptr %p, i64 1
|
|
%2 = ptrtoint ptr %p to i64
|
|
%3 = getelementptr inbounds i32, ptr %1, i64 %2
|
|
ret ptr %3
|
|
}
|
|
|
|
; It is valid to swap if the second GEP has multiple uses.
|
|
define ptr @multipleUses2(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @multipleUses2(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[P:%.*]], i64 4
|
|
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [4 x i8], ptr [[TMP1]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: call void @use(ptr nonnull [[TMP2]])
|
|
; CHECK-NEXT: ret ptr [[TMP2]]
|
|
;
|
|
%1 = getelementptr inbounds i32, ptr %p, i64 1
|
|
%2 = getelementptr inbounds i32, ptr %1, i64 %a
|
|
call void @use(ptr %2)
|
|
ret ptr %2
|
|
}
|
|
|
|
; Negative test. It is not valid to swap if the first GEP has multiple uses.
|
|
define ptr @multipleUses3(ptr %p) {
|
|
; CHECK-LABEL: @multipleUses3(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[P:%.*]], i64 4
|
|
; CHECK-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[TMP1]] to i64
|
|
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [4 x i8], ptr [[TMP1]], i64 [[TMP2]]
|
|
; CHECK-NEXT: ret ptr [[TMP3]]
|
|
;
|
|
%1 = getelementptr inbounds i32, ptr %p, i64 1
|
|
%2 = ptrtoint ptr %1 to i64
|
|
%3 = getelementptr inbounds i32, ptr %1, i64 %2
|
|
ret ptr %3
|
|
}
|
|
|
|
define ptr @merge_nuw(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_nuw(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr nuw [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr nuw i8, ptr [[GEP2]], i64 5
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr nuw i8, ptr %p, i64 1
|
|
%gep2 = getelementptr nuw i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr nuw i32, ptr %gep2, i64 1
|
|
ret ptr %gep3
|
|
}
|
|
|
|
define ptr @merge_nuw_inbounds(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_nuw_inbounds(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr inbounds nuw i8, ptr [[GEP2]], i64 5
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr inbounds nuw i8, ptr %p, i64 1
|
|
%gep2 = getelementptr inbounds nuw i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr inbounds nuw i32, ptr %gep2, i64 1
|
|
ret ptr %gep3
|
|
}
|
|
|
|
; It would be okay to preserve nusw here, as the constant addition does not
|
|
; overflow.
|
|
define ptr @merge_nuw_nusw(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_nuw_nusw(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr nusw nuw [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr nuw i8, ptr [[GEP2]], i64 5
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr nusw nuw i8, ptr %p, i64 1
|
|
%gep2 = getelementptr nusw nuw i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr nusw nuw i32, ptr %gep2, i64 1
|
|
ret ptr %gep3
|
|
}
|
|
|
|
; Can't preserve nusw on the final GEP
|
|
define ptr @merge_nuw_nusw_overflow(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_nuw_nusw_overflow(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr nusw nuw [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr nuw i8, ptr [[GEP2]], i64 -2305843009213693952
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr nusw nuw i8, ptr %p, i64 u0x7000000000000000
|
|
%gep2 = getelementptr nusw nuw i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr nusw nuw i8, ptr %gep2, i64 u0x7000000000000000
|
|
ret ptr %gep3
|
|
}
|
|
|
|
define ptr @merge_missing_nuw1(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_missing_nuw1(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP2]], i64 5
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr i8, ptr %p, i64 1
|
|
%gep2 = getelementptr nuw i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr nuw i32, ptr %gep2, i64 1
|
|
ret ptr %gep3
|
|
}
|
|
|
|
define ptr @merge_missing_nuw2(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_missing_nuw2(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP2]], i64 5
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr nuw i8, ptr %p, i64 1
|
|
%gep2 = getelementptr i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr nuw i32, ptr %gep2, i64 1
|
|
ret ptr %gep3
|
|
}
|
|
|
|
define ptr @merge_missing_nuw3(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_missing_nuw3(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr nuw [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP2]], i64 5
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr nuw i8, ptr %p, i64 1
|
|
%gep2 = getelementptr nuw i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr i32, ptr %gep2, i64 1
|
|
ret ptr %gep3
|
|
}
|
|
|
|
define ptr @merge_nuw_missing_inbounds(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_nuw_missing_inbounds(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr nuw [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr nuw i8, ptr [[GEP2]], i64 5
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr nuw i8, ptr %p, i64 1
|
|
%gep2 = getelementptr inbounds nuw i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr inbounds nuw i32, ptr %gep2, i64 1
|
|
ret ptr %gep3
|
|
}
|
|
|
|
define ptr @merge_nuw_missing_nusw(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_nuw_missing_nusw(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr nuw [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr nuw i8, ptr [[GEP2]], i64 5
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr nusw nuw i8, ptr %p, i64 1
|
|
%gep2 = getelementptr nuw i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr nusw nuw i32, ptr %gep2, i64 1
|
|
ret ptr %gep3
|
|
}
|
|
|
|
define ptr @merge_inbounds_missing_nuw(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_inbounds_missing_nuw(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP2]], i64 5
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr inbounds nuw i8, ptr %p, i64 1
|
|
%gep2 = getelementptr inbounds i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr inbounds nuw i32, ptr %gep2, i64 1
|
|
ret ptr %gep3
|
|
}
|
|
|
|
define ptr @merge_nusw_missing_nuw(ptr %p, i64 %a) {
|
|
; CHECK-LABEL: @merge_nusw_missing_nuw(
|
|
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr [4 x i8], ptr [[P:%.*]], i64 [[A:%.*]]
|
|
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP2]], i64 5
|
|
; CHECK-NEXT: ret ptr [[GEP3]]
|
|
;
|
|
%gep1 = getelementptr nusw nuw i8, ptr %p, i64 1
|
|
%gep2 = getelementptr nusw i32, ptr %gep1, i64 %a
|
|
%gep3 = getelementptr nusw nuw i32, ptr %gep2, i64 1
|
|
ret ptr %gep3
|
|
}
|