Files
TheRock/compiler/amd-llvm/llvm/test/Transforms/InstCombine/gep-fold-chained-const-select.ll
T
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

216 lines
8.9 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
; RUN: opt < %s -S -passes=instcombine | FileCheck %s
define ptr @src_origin(i32 %arg0, ptr %arg1) !prof !0 {
; CHECK-LABEL: @src_origin(
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[V1]], i64 63252, i64 29452, !prof [[PROF1:![0-9]+]]
; CHECK-NEXT: [[V3:%.*]] = getelementptr i8, ptr [[ARG1:%.*]], i64 [[TMP1]]
; CHECK-NEXT: ret ptr [[V3]]
;
%v0 = getelementptr i8, ptr %arg1, i64 8148
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, i64 55104, i64 21304, !prof !1
%v3 = getelementptr i8, ptr %v0, i64 %v2
ret ptr %v3
}
define ptr @src_nuw(i32 %arg0, ptr %arg1) !prof !0 {
; CHECK-LABEL: @src_nuw(
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[V1]], i64 63252, i64 29452, !prof [[PROF1]]
; CHECK-NEXT: [[V3:%.*]] = getelementptr nuw i8, ptr [[ARG1:%.*]], i64 [[TMP1]]
; CHECK-NEXT: ret ptr [[V3]]
;
%v0 = getelementptr nuw i8, ptr %arg1, i64 8148
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, i64 55104, i64 21304, !prof !1
%v3 = getelementptr nuw i8, ptr %v0, i64 %v2
ret ptr %v3
}
define ptr @src_inbounds_nuw(i32 %arg0, ptr %arg1) !prof !0 {
; CHECK-LABEL: @src_inbounds_nuw(
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[V1]], i64 63252, i64 29452, !prof [[PROF1]]
; CHECK-NEXT: [[V3:%.*]] = getelementptr nuw i8, ptr [[ARG1:%.*]], i64 [[TMP1]]
; CHECK-NEXT: ret ptr [[V3]]
;
%v0 = getelementptr inbounds nuw i8, ptr %arg1, i64 8148
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, i64 55104, i64 21304, !prof !1
%v3 = getelementptr nuw i8, ptr %v0, i64 %v2
ret ptr %v3
}
define ptr @src_swap(i32 %arg0, ptr %arg1) !prof !0{
; CHECK-LABEL: @src_swap(
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[V1]], i64 63252, i64 29452, !prof [[PROF1]]
; CHECK-NEXT: [[V0:%.*]] = getelementptr i8, ptr [[ARG1:%.*]], i64 [[TMP1]]
; CHECK-NEXT: ret ptr [[V0]]
;
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, i64 55104, i64 21304, !prof !1
%v0 = getelementptr i8, ptr %arg1, i64 %v2
%v3 = getelementptr i8, ptr %v0, i64 8148
ret ptr %v3
}
define <2 x ptr> @src_splat(i32 %arg0, <2 x ptr> %arg1) {
; CHECK-LABEL: @src_splat(
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[V1]], <2 x i64> splat (i64 63252), <2 x i64> splat (i64 29452)
; CHECK-NEXT: [[V3:%.*]] = getelementptr i8, <2 x ptr> [[ARG1:%.*]], <2 x i64> [[TMP1]]
; CHECK-NEXT: ret <2 x ptr> [[V3]]
;
%v0 = getelementptr i8, <2 x ptr> %arg1, <2 x i64> splat (i64 8148)
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, <2 x i64> splat (i64 55104), <2 x i64> splat (i64 21304)
%v3 = getelementptr i8, <2 x ptr> %v0, <2 x i64> %v2
ret <2 x ptr> %v3
}
define <2 x ptr> @src_splat_scalar_ptr(i32 %arg0, ptr %arg1) {
; CHECK-LABEL: @src_splat_scalar_ptr(
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[V1]], <2 x i64> splat (i64 63252), <2 x i64> splat (i64 29452)
; CHECK-NEXT: [[V3:%.*]] = getelementptr i8, ptr [[ARG1:%.*]], <2 x i64> [[TMP1]]
; CHECK-NEXT: ret <2 x ptr> [[V3]]
;
%v0 = getelementptr i8, ptr %arg1, <2 x i64> splat (i64 8148)
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, <2 x i64> splat (i64 55104), <2 x i64> splat (i64 21304)
%v3 = getelementptr i8, <2 x ptr> %v0, <2 x i64> %v2
ret <2 x ptr> %v3
}
; Fail 1: Different GEP type
define ptr @src_fail_different_type(i32 %arg0, ptr %arg1) {
; CHECK-LABEL: @src_fail_different_type(
; CHECK-NEXT: [[V0:%.*]] = getelementptr inbounds nuw i8, ptr [[ARG1:%.*]], i64 8148
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[V2:%.*]] = select i1 [[V1]], i64 55104, i64 21304
; CHECK-NEXT: [[V3:%.*]] = getelementptr [2 x i8], ptr [[V0]], i64 [[V2]]
; CHECK-NEXT: ret ptr [[V3]]
;
%v0 = getelementptr inbounds nuw i8, ptr %arg1, i64 8148
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, i64 55104, i64 21304
%v3 = getelementptr i16, ptr %v0, i64 %v2
ret ptr %v3
}
; Fail 2: No constant idx
define ptr @src_fail_no_constant_idx(i32 %arg0, ptr %arg1, i64 %arg2) {
; CHECK-LABEL: @src_fail_no_constant_idx(
; CHECK-NEXT: [[V0:%.*]] = getelementptr inbounds nuw i8, ptr [[ARG1:%.*]], i64 [[ARG2:%.*]]
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[V2:%.*]] = select i1 [[V1]], i64 55104, i64 21304
; CHECK-NEXT: [[V3:%.*]] = getelementptr i8, ptr [[V0]], i64 [[V2]]
; CHECK-NEXT: ret ptr [[V3]]
;
%v0 = getelementptr inbounds nuw i8, ptr %arg1, i64 %arg2
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, i64 55104, i64 21304
%v3 = getelementptr i8, ptr %v0, i64 %v2
ret ptr %v3
}
; Fail 3: Multiple use of select
define ptr @src_fail_select_multiple_use(i32 %arg0, ptr %arg1, ptr %arg2) {
; CHECK-LABEL: @src_fail_select_multiple_use(
; CHECK-NEXT: [[V0:%.*]] = getelementptr inbounds nuw i8, ptr [[ARG1:%.*]], i64 8148
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[V2:%.*]] = select i1 [[V1]], i64 55104, i64 21304
; CHECK-NEXT: [[V3:%.*]] = getelementptr i8, ptr [[V0]], i64 [[V2]]
; CHECK-NEXT: [[V4:%.*]] = getelementptr i8, ptr [[ARG2:%.*]], i64 [[V2]]
; CHECK-NEXT: store ptr [[V3]], ptr [[V4]], align 8
; CHECK-NEXT: ret ptr [[V3]]
;
%v0 = getelementptr inbounds nuw i8, ptr %arg1, i64 8148
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, i64 55104, i64 21304
%v3 = getelementptr i8, ptr %v0, i64 %v2
%v4 = getelementptr i8, ptr %arg2, i64 %v2
store ptr %v3, ptr %v4, align 8
ret ptr %v3
}
declare void @use(ptr)
; Fail 4: Multiple use of source GEP
define ptr @src_fail_source_gep_multiple_use(i32 %arg0, ptr %arg1, ptr %arg2) {
; CHECK-LABEL: @src_fail_source_gep_multiple_use(
; CHECK-NEXT: [[V0:%.*]] = getelementptr inbounds nuw i8, ptr [[ARG1:%.*]], i64 8148
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[V2:%.*]] = select i1 [[V1]], i64 55104, i64 21304
; CHECK-NEXT: call void @use(ptr nonnull [[V0]])
; CHECK-NEXT: [[V3:%.*]] = getelementptr i8, ptr [[V0]], i64 [[V2]]
; CHECK-NEXT: ret ptr [[V3]]
;
%v0 = getelementptr inbounds nuw i8, ptr %arg1, i64 8148
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, i64 55104, i64 21304
call void @use(ptr %v0)
%v3 = getelementptr i8, ptr %v0, i64 %v2
ret ptr %v3
}
define ptr @src_fail_source_gep_multiple_swap(i32 %arg0, ptr %arg1) {
; CHECK-LABEL: @src_fail_source_gep_multiple_swap(
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[V2:%.*]] = select i1 [[V1]], i64 55104, i64 21304
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds nuw i8, ptr [[ARG1:%.*]], i64 [[V2]]
; CHECK-NEXT: call void @use(ptr nonnull [[GEP1]])
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr [[GEP1]], i64 8148
; CHECK-NEXT: ret ptr [[GEP2]]
;
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, i64 55104, i64 21304
%gep1 = getelementptr inbounds nuw i8, ptr %arg1, i64 %v2
call void @use(ptr %gep1)
%gep2 = getelementptr i8, ptr %gep1, i64 8148
ret ptr %gep2
}
; TODO: constant vector index
define <2 x ptr> @fail_vector_const_vector_select(i32 %arg0, <2 x ptr> %arg1) {
; CHECK-LABEL: @fail_vector_const_vector_select(
; CHECK-NEXT: [[V0:%.*]] = getelementptr i8, <2 x ptr> [[ARG1:%.*]], <2 x i64> <i64 8148, i64 8848>
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[V2:%.*]] = select i1 [[V1]], <2 x i64> <i64 55104, i64 56654>, <2 x i64> <i64 21304, i64 21224>
; CHECK-NEXT: [[V3:%.*]] = getelementptr i8, <2 x ptr> [[V0]], <2 x i64> [[V2]]
; CHECK-NEXT: ret <2 x ptr> [[V3]]
;
%v0 = getelementptr i8, <2 x ptr> %arg1, <2 x i64> <i64 8148, i64 8848>
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, <2 x i64> <i64 55104, i64 56654>, <2 x i64> <i64 21304, i64 21224>
%v3 = getelementptr i8, <2 x ptr> %v0, <2 x i64> %v2
ret <2 x ptr> %v3
}
define <2 x ptr> @fail_scalar_const_vector_select(i32 %arg0, <2 x ptr> %arg1) {
; CHECK-LABEL: @fail_scalar_const_vector_select(
; CHECK-NEXT: [[V0:%.*]] = getelementptr i8, <2 x ptr> [[ARG1:%.*]], i64 8148
; CHECK-NEXT: [[V1:%.*]] = icmp sgt i32 [[ARG0:%.*]], 3
; CHECK-NEXT: [[V2:%.*]] = select i1 [[V1]], <2 x i64> <i64 55104, i64 56654>, <2 x i64> <i64 21304, i64 21224>
; CHECK-NEXT: [[V3:%.*]] = getelementptr i8, <2 x ptr> [[V0]], <2 x i64> [[V2]]
; CHECK-NEXT: ret <2 x ptr> [[V3]]
;
%v0 = getelementptr i8, <2 x ptr> %arg1, i64 8148
%v1 = icmp sgt i32 %arg0, 3
%v2 = select i1 %v1, <2 x i64> <i64 55104, i64 56654>, <2 x i64> <i64 21304, i64 21224>
%v3 = getelementptr i8, <2 x ptr> %v0, <2 x i64> %v2
ret <2 x ptr> %v3
}
!0 = !{!"function_entry_count", i32 10}
!1 = !{!"branch_weights", i32 5, i32 3}
;.
; CHECK: [[META0:![0-9]+]] = !{!"function_entry_count", i32 10}
; CHECK: [[PROF1]] = !{!"branch_weights", i32 5, i32 3}
;.