Files
TheRock/compiler/amd-llvm/llvm/test/Transforms/InstCombine/memchr-2.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

127 lines
3.2 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
; Verify that memchr calls with constant arrays, or constant characters,
; or constant bounds are folded (or not) as expected.
declare ptr @memchr(ptr, i32, i64)
@ax = external global [0 x i8]
@a12345 = constant [5 x i8] c"\01\02\03\04\05"
@a123f45 = constant [5 x i8] c"\01\02\03\f4\05"
; Fold memchr(a12345, '\06', n) to null.
define ptr @fold_memchr_a12345_6_n(i64 %n) {
; CHECK-LABEL: @fold_memchr_a12345_6_n(
; CHECK-NEXT: ret ptr null
;
%res = call ptr @memchr(ptr @a12345, i32 6, i64 %n)
ret ptr %res
}
; Fold memchr(a12345, '\04', 2) to null.
define ptr @fold_memchr_a12345_4_2() {
; CHECK-LABEL: @fold_memchr_a12345_4_2(
; CHECK-NEXT: ret ptr null
;
%res = call ptr @memchr(ptr @a12345, i32 4, i64 2)
ret ptr %res
}
; Fold memchr(a12345, '\04', 3) to null.
define ptr @fold_memchr_a12345_4_3() {
; CHECK-LABEL: @fold_memchr_a12345_4_3(
; CHECK-NEXT: ret ptr null
;
%res = call ptr @memchr(ptr @a12345, i32 4, i64 3)
ret ptr %res
}
; Fold memchr(a12345, '\03', 3) to a12345 + 2.
define ptr @fold_memchr_a12345_3_3() {
; CHECK-LABEL: @fold_memchr_a12345_3_3(
; CHECK-NEXT: ret ptr getelementptr inbounds nuw (i8, ptr @a12345, i64 2)
;
%res = call ptr @memchr(ptr @a12345, i32 3, i64 3)
ret ptr %res
}
; Fold memchr(a12345, '\03', 9) to a12345 + 2.
define ptr @fold_memchr_a12345_3_9() {
; CHECK-LABEL: @fold_memchr_a12345_3_9(
; CHECK-NEXT: ret ptr getelementptr inbounds nuw (i8, ptr @a12345, i64 2)
;
%res = call ptr @memchr(ptr @a12345, i32 3, i64 9)
ret ptr %res
}
; Fold memchr(a123f45, 500, 9) to a123f45 + 3 (verify that 500 is
; truncated to (unsigned char)500 == '\xf4')
define ptr @fold_memchr_a123f45_500_9() {
; CHECK-LABEL: @fold_memchr_a123f45_500_9(
; CHECK-NEXT: ret ptr getelementptr inbounds nuw (i8, ptr @a123f45, i64 3)
;
%res = call ptr @memchr(ptr @a123f45, i32 500, i64 9)
ret ptr %res
}
; Fold memchr(a12345, '\03', n) to n < 3 ? null : a12345 + 2.
define ptr @fold_a12345_3_n(i64 %n) {
; CHECK-LABEL: @fold_a12345_3_n(
; CHECK-NEXT: [[MEMCHR_CMP:%.*]] = icmp ult i64 [[N:%.*]], 3
; CHECK-NEXT: [[RES:%.*]] = select i1 [[MEMCHR_CMP]], ptr null, ptr getelementptr inbounds nuw (i8, ptr @a12345, i64 2)
; CHECK-NEXT: ret ptr [[RES]]
;
%res = call ptr @memchr(ptr @a12345, i32 3, i64 %n)
ret ptr %res
}
; Fold memchr(a12345, 259, n) to n < 3 ? null : a12345 + 2
; to verify the constant 259 is converted to unsigned char (yielding 3).
define ptr @fold_a12345_259_n(i64 %n) {
; CHECK-LABEL: @fold_a12345_259_n(
; CHECK-NEXT: [[MEMCHR_CMP:%.*]] = icmp ult i64 [[N:%.*]], 3
; CHECK-NEXT: [[RES:%.*]] = select i1 [[MEMCHR_CMP]], ptr null, ptr getelementptr inbounds nuw (i8, ptr @a12345, i64 2)
; CHECK-NEXT: ret ptr [[RES]]
;
%res = call ptr @memchr(ptr @a12345, i32 259, i64 %n)
ret ptr %res
}
; Do no fold memchr(ax, 1, n).
define ptr @call_ax_1_n(i64 %n) {
; CHECK-LABEL: @call_ax_1_n(
; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr nonnull @ax, i32 1, i64 [[N:%.*]])
; CHECK-NEXT: ret ptr [[RES]]
;
%res = call ptr @memchr(ptr @ax, i32 1, i64 %n)
ret ptr %res
}