Files
TheRock/compiler/amd-llvm/llvm/test/Analysis/ValueTracking/numsignbits-shl.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

161 lines
6.5 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -passes=instcombine -S < %s | FileCheck %s
declare void @escape(i16 %add)
declare void @escape2(<2 x i16> %add)
define void @numsignbits_shl_zext(i8 %x) {
; CHECK-LABEL: define void @numsignbits_shl_zext(
; CHECK-SAME: i8 [[X:%.*]]) {
; CHECK-NEXT: [[ASHR:%.*]] = ashr i8 [[X]], 5
; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[ASHR]] to i16
; CHECK-NEXT: [[NSB4:%.*]] = shl i16 [[ZEXT]], 10
; CHECK-NEXT: [[ADD14:%.*]] = and i16 [[NSB4]], 15360
; CHECK-NEXT: call void @escape(i16 [[ADD14]])
; CHECK-NEXT: [[ADD13:%.*]] = and i16 [[NSB4]], 7168
; CHECK-NEXT: call void @escape(i16 [[ADD13]])
; CHECK-NEXT: [[ADD12:%.*]] = and i16 [[NSB4]], 3072
; CHECK-NEXT: call void @escape(i16 [[ADD12]])
; CHECK-NEXT: [[AND11:%.*]] = and i16 [[NSB4]], 2048
; CHECK-NEXT: [[ADD11:%.*]] = add nsw i16 [[AND11]], [[NSB4]]
; CHECK-NEXT: call void @escape(i16 [[ADD11]])
; CHECK-NEXT: ret void
;
%ashr = ashr i8 %x, 5
%zext = zext i8 %ashr to i16
%nsb4 = shl i16 %zext, 10
; Validate ComputeNumSignBits using this simplification:
; (A & 2^C1) + A => A & (2^C1 - 1) iff bit C1 in A is a sign bit
; 4 sign bits: Goal is to fold away the add for bits 12-14.
%and14 = and i16 %nsb4, 16384
%add14 = add i16 %and14, %nsb4
call void @escape(i16 %add14)
%and13 = and i16 %nsb4, 8192
%add13 = add i16 %and13, %nsb4
call void @escape(i16 %add13)
%and12 = and i16 %nsb4, 4096
%add12 = add i16 %and12, %nsb4
call void @escape(i16 %add12)
%and11 = and i16 %nsb4, 2048
%add11 = add i16 %and11, %nsb4
call void @escape(i16 %add11)
ret void
}
define void @numsignbits_shl_zext_shift_amounr_matches_extend(i8 %x) {
; CHECK-LABEL: define void @numsignbits_shl_zext_shift_amounr_matches_extend(
; CHECK-SAME: i8 [[X:%.*]]) {
; CHECK-NEXT: [[ASHR:%.*]] = ashr i8 [[X]], 2
; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[ASHR]] to i16
; CHECK-NEXT: [[NSB3:%.*]] = shl nuw i16 [[ZEXT]], 8
; CHECK-NEXT: [[ADD14:%.*]] = and i16 [[NSB3]], 16128
; CHECK-NEXT: call void @escape(i16 [[ADD14]])
; CHECK-NEXT: [[ADD13:%.*]] = and i16 [[NSB3]], 7936
; CHECK-NEXT: call void @escape(i16 [[ADD13]])
; CHECK-NEXT: [[AND12:%.*]] = and i16 [[NSB3]], 4096
; CHECK-NEXT: [[ADD12:%.*]] = add nsw i16 [[AND12]], [[NSB3]]
; CHECK-NEXT: call void @escape(i16 [[ADD12]])
; CHECK-NEXT: ret void
;
%ashr = ashr i8 %x, 2
%zext = zext i8 %ashr to i16
%nsb3 = shl i16 %zext, 8
; Validate ComputeNumSignBits using this simplification:
; (A & 2^C1) + A => A & (2^C1 - 1) iff bit C1 in A is a sign bit
; 3 sign bits: Goal is to fold away the add for bits 13-14.
%and14 = and i16 %nsb3, 16384
%add14 = add i16 %and14, %nsb3
call void @escape(i16 %add14)
%and13 = and i16 %nsb3, 8192
%add13 = add i16 %and13, %nsb3
call void @escape(i16 %add13)
%and12 = and i16 %nsb3, 4096
%add12 = add i16 %and12, %nsb3
call void @escape(i16 %add12)
ret void
}
define void @numsignbits_shl_zext_extended_bits_remains(i8 %x) {
; CHECK-LABEL: define void @numsignbits_shl_zext_extended_bits_remains(
; CHECK-SAME: i8 [[X:%.*]]) {
; CHECK-NEXT: [[ASHR:%.*]] = ashr i8 [[X]], 5
; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[ASHR]] to i16
; CHECK-NEXT: [[NSB1:%.*]] = shl nuw nsw i16 [[ZEXT]], 7
; CHECK-NEXT: [[AND14:%.*]] = and i16 [[NSB1]], 16384
; CHECK-NEXT: [[ADD14:%.*]] = add nuw i16 [[AND14]], [[NSB1]]
; CHECK-NEXT: call void @escape(i16 [[ADD14]])
; CHECK-NEXT: ret void
;
%ashr = ashr i8 %x, 5
%zext = zext i8 %ashr to i16
%nsb1 = shl i16 %zext, 7
; Validate ComputeNumSignBits using this simplification:
; (A & 2^C1) + A => A & (2^C1 - 1) iff bit C1 in A is a sign bit
; 1 sign bit: The add can't be folded away here.
%and14 = and i16 %nsb1, 16384
%add14 = add i16 %and14, %nsb1
call void @escape(i16 %add14)
ret void
}
define void @numsignbits_shl_zext_all_bits_shifted_out(i8 %x) {
; CHECK-LABEL: define void @numsignbits_shl_zext_all_bits_shifted_out(
; CHECK-SAME: i8 [[X:%.*]]) {
; CHECK-NEXT: [[ASHR:%.*]] = lshr i8 [[X]], 5
; CHECK-NEXT: [[ZEXT:%.*]] = zext nneg i8 [[ASHR]] to i16
; CHECK-NEXT: [[NSB1:%.*]] = shl i16 [[ZEXT]], 14
; CHECK-NEXT: [[AND14:%.*]] = and i16 [[NSB1]], 16384
; CHECK-NEXT: [[ADD14:%.*]] = add i16 [[AND14]], [[NSB1]]
; CHECK-NEXT: call void @escape(i16 [[ADD14]])
; CHECK-NEXT: ret void
;
%ashr = ashr i8 %x, 5
%zext = zext i8 %ashr to i16
%nsb1 = shl i16 %zext, 14
; Validate ComputeNumSignBits using this simplification:
; (A & 2^C1) + A => A & (2^C1 - 1) iff bit C1 in A is a sign bit
; 1 sign bit: The add can't be folded away here.
%and14 = and i16 %nsb1, 16384
%add14 = add i16 %and14, %nsb1
call void @escape(i16 %add14)
ret void
}
define void @numsignbits_shl_zext_vector(<2 x i8> %x) {
; CHECK-LABEL: define void @numsignbits_shl_zext_vector(
; CHECK-SAME: <2 x i8> [[X:%.*]]) {
; CHECK-NEXT: [[ASHR:%.*]] = ashr <2 x i8> [[X]], splat (i8 5)
; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i8> [[ASHR]] to <2 x i16>
; CHECK-NEXT: [[NSB4:%.*]] = shl <2 x i16> [[ZEXT]], splat (i16 10)
; CHECK-NEXT: [[ADD14:%.*]] = and <2 x i16> [[NSB4]], splat (i16 15360)
; CHECK-NEXT: call void @escape2(<2 x i16> [[ADD14]])
; CHECK-NEXT: [[ADD13:%.*]] = and <2 x i16> [[NSB4]], splat (i16 7168)
; CHECK-NEXT: call void @escape2(<2 x i16> [[ADD13]])
; CHECK-NEXT: [[ADD12:%.*]] = and <2 x i16> [[NSB4]], splat (i16 3072)
; CHECK-NEXT: call void @escape2(<2 x i16> [[ADD12]])
; CHECK-NEXT: [[AND11:%.*]] = and <2 x i16> [[NSB4]], splat (i16 2048)
; CHECK-NEXT: [[ADD11:%.*]] = add nsw <2 x i16> [[AND11]], [[NSB4]]
; CHECK-NEXT: call void @escape2(<2 x i16> [[ADD11]])
; CHECK-NEXT: ret void
;
%ashr = ashr <2 x i8> %x, <i8 5, i8 5>
%zext = zext <2 x i8> %ashr to <2 x i16>
%nsb4 = shl <2 x i16> %zext, <i16 10, i16 10>
; Validate ComputeNumSignBits using this simplification:
; (A & 2^C1) + A => A & (2^C1 - 1) iff bit C1 in A is a sign bit
; 4 sign bits: Goal is to fold away the add for bits 12-14.
%and14 = and <2 x i16> %nsb4, <i16 16384, i16 16384>
%add14 = add <2 x i16> %and14, %nsb4
call void @escape2(<2 x i16> %add14)
%and13 = and <2 x i16> %nsb4, <i16 8192, i16 8192>
%add13 = add <2 x i16> %and13, %nsb4
call void @escape2(<2 x i16> %add13)
%and12 = and <2 x i16> %nsb4, <i16 4096, i16 4096>
%add12 = add <2 x i16> %and12, %nsb4
call void @escape2(<2 x i16> %add12)
%and11 = and <2 x i16> %nsb4, <i16 2048, i16 2048>
%add11 = add <2 x i16> %and11, %nsb4
call void @escape2(<2 x i16> %add11)
ret void
}