Files
TheRock/compiler/amd-llvm/flang/test/Fir/peephole.fir
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

128 lines
3.7 KiB
Plaintext

// RUN: tco %s | FileCheck %s
// RUN: %flang_fc1 -emit-llvm %s -o - | FileCheck %s
// Test peephole optimizations
// CHECK-LABEL: define i8 @test_trunc(
// CHECK-SAME: i256 %[[arg:.*]])
// CHECK-NEXT: = trunc i256 %[[arg]] to i8
// CHECK-NEXT: ret i8
func.func @test_trunc(%0 : i256) -> i8 {
%1 = fir.convert %0 : (i256) -> i128
%2 = fir.convert %1 : (i128) -> i64
%3 = fir.convert %2 : (i64) -> i32
%4 = fir.convert %3 : (i32) -> i16
%5 = fir.convert %4 : (i16) -> i8
return %5 : i8
}
// CHECK-LABEL: define i256 @test_sext(
// CHECK-SAME: i8 %[[arg:.*]])
// CHECK-NEXT: = sext i8 %[[arg]] to i256
// CHECK-NEXT: ret i256
func.func @test_sext(%0 : i8) -> i256 {
%1 = fir.convert %0 : (i8) -> i16
%2 = fir.convert %1 : (i16) -> i32
%3 = fir.convert %2 : (i32) -> i64
%4 = fir.convert %3 : (i64) -> i128
%5 = fir.convert %4 : (i128) -> i256
return %5 : i256
}
// CHECK-LABEL: define half @test_fptrunc(
// CHECK-SAME: fp128 %[[arg:.*]])
// CHECK-NEXT: %[[res:.*]] = fptrunc fp128 %[[arg]] to half
// CHECK-NEXT: ret half %[[res]]
func.func @test_fptrunc(%0 : f128) -> f16 {
%2 = fir.convert %0 : (f128) -> f64
%3 = fir.convert %2 : (f64) -> f32
%4 = fir.convert %3 : (f32) -> f16
return %4 : f16
}
// CHECK-LABEL: define x86_fp80 @test_fpext(
// CHECK-SAME: bfloat %[[arg:.*]])
// CHECK-NEXT: = fpext bfloat %[[arg]] to x86_fp80
// CHECK-NEXT: ret x86_fp80
func.func @test_fpext(%0 : bf16) -> f80 {
%2 = fir.convert %0 : (bf16) -> f32
%3 = fir.convert %2 : (f32) -> f64
%4 = fir.convert %3 : (f64) -> f80
return %4 : f80
}
// CHECK-LABEL: define i64 @test_ascending(
// CHECK-SAME: i8 %[[arg:.*]])
// CHECK-NEXT: = sext i8 %[[arg]] to i64
// CHECK-NEXT: ret i64
func.func @test_ascending(%0 : i8) -> index {
%1 = fir.convert %0 : (i8) -> i16
%2 = fir.convert %1 : (i16) -> i32
%3 = fir.convert %2 : (i32) -> i64
%5 = fir.convert %3 : (i64) -> index
return %5 : index
}
// CHECK-LABEL: define i8 @test_descending(
// CHECK-SAME: i64 %[[arg:.*]])
// CHECK-NEXT: = trunc i64 %[[arg]] to i8
// CHECK-NEXT: ret i8
func.func @test_descending(%0 : index) -> i8 {
%2 = fir.convert %0 : (index) -> i64
%3 = fir.convert %2 : (i64) -> i32
%4 = fir.convert %3 : (i32) -> i16
%5 = fir.convert %4 : (i16) -> i8
return %5 : i8
}
// CHECK-LABEL: define float @test_useless(
// CHECK-SAME: float %[[arg:.*]])
// CHECK-NEXT: ret float %[[arg]]
func.func @test_useless(%0 : f32) -> f32 {
%1 = fir.convert %0 : (f32) -> f32
return %1 : f32
}
// CHECK-LABEL: define float @test_useless_sext(
// CHECK-SAME: i32 %[[arg:.*]])
// CHECK-NEXT: %[[res:.*]] = sitofp i32 %[[arg]] to float
// CHECK-NEXT: ret float %[[res]]
func.func @test_useless_sext(%0 : i32) -> f32 {
%1 = fir.convert %0 : (i32) -> i64
%2 = fir.convert %1 : (i64) -> i32
%3 = fir.convert %2 : (i32) -> f32
return %3 : f32
}
// CHECK-LABEL: define i16 @test_hump(
// CHECK-SAME: i32 %[[arg:.*]])
// CHECK-NEXT: trunc i32 %[[arg]] to i16
// CHECK-NEXT: ret i16
func.func @test_hump(%0 : i32) -> i16 {
%1 = fir.convert %0 : (i32) -> i64
%2 = fir.convert %1 : (i64) -> i16
return %2 : i16
}
// CHECK-LABEL: define i16 @test_slump(
// CHECK-SAME: i32 %[[arg:.*]])
// CHECK-NEXT: %[[i:.*]] = trunc i32 %[[arg]] to i8
// CHECK-NEXT: sext i8 %[[i]] to i16
// CHECK-NEXT: ret i16
func.func @test_slump(%0 : i32) -> i16 {
%1 = fir.convert %0 : (i32) -> i8
%2 = fir.convert %1 : (i8) -> i16
return %2 : i16
}
// CHECK-LABEL: define i64 @test_slump2(
// CHECK-SAME: i64 %[[arg:.*]])
// CHECK-NEXT: %[[i:.*]] = trunc i64 %[[arg]] to i16
// CHECK-NEXT: sext i16 %[[i]] to i64
// CHECK-NEXT: ret i64
func.func @test_slump2(%0 : index) -> index {
%1 = fir.convert %0 : (index) -> i16
%2 = fir.convert %1 : (i16) -> index
return %2 : index
}