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

79 lines
2.1 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
;
; Verify that the result of strchr calls used in equality expressions
; with either the first argument or null are optimally folded.
declare ptr @strchr(ptr, i32)
; Fold strchr(s, c) == s to *s == c.
define i1 @fold_strchr_s_c_eq_s(ptr %s, i32 %c) {
; CHECK-LABEL: @fold_strchr_s_c_eq_s(
; CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[S:%.*]], align 1
; CHECK-NEXT: [[TMP2:%.*]] = trunc i32 [[C:%.*]] to i8
; CHECK-NEXT: [[CHAR0CMP:%.*]] = icmp eq i8 [[TMP1]], [[TMP2]]
; CHECK-NEXT: ret i1 [[CHAR0CMP]]
;
%p = call ptr @strchr(ptr %s, i32 %c)
%cmp = icmp eq ptr %p, %s
ret i1 %cmp
}
; Fold strchr(s, c) != s to *s != c.
define i1 @fold_strchr_s_c_neq_s(ptr %s, i32 %c) {
; CHECK-LABEL: @fold_strchr_s_c_neq_s(
; CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[S:%.*]], align 1
; CHECK-NEXT: [[TMP2:%.*]] = trunc i32 [[C:%.*]] to i8
; CHECK-NEXT: [[CHAR0CMP:%.*]] = icmp ne i8 [[TMP1]], [[TMP2]]
; CHECK-NEXT: ret i1 [[CHAR0CMP]]
;
%p = call ptr @strchr(ptr %s, i32 %c)
%cmp = icmp ne ptr %p, %s
ret i1 %cmp
}
; Fold strchr(s, '\0') == null to false. (A string must be nul-terminated,
; otherwise the call would read past the end of the array.)
define i1 @fold_strchr_s_nul_eqz(ptr %s) {
; CHECK-LABEL: @fold_strchr_s_nul_eqz(
; CHECK-NEXT: ret i1 false
;
%p = call ptr @strchr(ptr %s, i32 0)
%cmp = icmp eq ptr %p, null
ret i1 %cmp
}
; Fold strchr(s, '\0') != null to true.
define i1 @fold_strchr_s_nul_nez(ptr %s) {
; CHECK-LABEL: @fold_strchr_s_nul_nez(
; CHECK-NEXT: ret i1 true
;
%p = call ptr @strchr(ptr %s, i32 0)
%cmp = icmp ne ptr %p, null
ret i1 %cmp
}
@a5 = constant [5 x i8] c"12345";
; Fold strchr(a5, c) == a5 to *a5 == c.
define i1 @fold_strchr_a_c_eq_a(i32 %c) {
; CHECK-LABEL: @fold_strchr_a_c_eq_a(
; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[C:%.*]] to i8
; CHECK-NEXT: [[CHAR0CMP:%.*]] = icmp eq i8 [[TMP1]], 49
; CHECK-NEXT: ret i1 [[CHAR0CMP]]
;
%q = call ptr @strchr(ptr @a5, i32 %c)
%cmp = icmp eq ptr %q, @a5
ret i1 %cmp
}