From 5a25b051a7b7c4bd273a1ad152af54ede93e271c Mon Sep 17 00:00:00 2001 From: DianQK Date: Sat, 3 Aug 2024 11:18:00 +0800 Subject: [PATCH] Add a set of tests for LLVM 19 --- .../issues/issue-107681-unwrap_unchecked.rs | 20 ++++++++++++++++ tests/codegen/issues/issue-118306.rs | 23 +++++++++++++++++++ tests/codegen/issues/issue-126585.rs | 23 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/codegen/issues/issue-107681-unwrap_unchecked.rs create mode 100644 tests/codegen/issues/issue-118306.rs create mode 100644 tests/codegen/issues/issue-126585.rs diff --git a/tests/codegen/issues/issue-107681-unwrap_unchecked.rs b/tests/codegen/issues/issue-107681-unwrap_unchecked.rs new file mode 100644 index 0000000000000..7d9679d2322b2 --- /dev/null +++ b/tests/codegen/issues/issue-107681-unwrap_unchecked.rs @@ -0,0 +1,20 @@ +//@ compile-flags: -O +//@ min-llvm-version: 19 + +// Test for #107681. +// Make sure we don't create `br` or `select` instructions. + +#![crate_type = "lib"] + +use std::iter::Copied; +use std::slice::Iter; + +#[no_mangle] +pub unsafe fn foo(x: &mut Copied>) -> u32 { + // CHECK-LABEL: @foo( + // CHECK-NOT: br + // CHECK-NOT: select + // CHECK: [[RET:%.*]] = load i32, ptr + // CHECK-NEXT: ret i32 [[RET]] + x.next().unwrap_unchecked() +} diff --git a/tests/codegen/issues/issue-118306.rs b/tests/codegen/issues/issue-118306.rs new file mode 100644 index 0000000000000..ef5865f2d01eb --- /dev/null +++ b/tests/codegen/issues/issue-118306.rs @@ -0,0 +1,23 @@ +//@ compile-flags: -O +//@ min-llvm-version: 19 + +// Test for #118306. +// Make sure we don't create `br` or `select` instructions. + +#![crate_type = "lib"] + +#[no_mangle] +pub fn branchy(input: u64) -> u64 { + // CHECK-LABEL: @branchy( + // CHECK-NOT: br + // CHECK-NOT: select + // CHECK-NOT: phi + // CHECK: [[SWITCH_GEP:%.*]] = getelementptr inbounds [4 x i64], ptr @switch.table.branchy + // CHECK-NEXT: [[SWITCH_LOAD:%.*]] = load i64, ptr [[SWITCH_GEP]] + // CHECK-NEXT: ret i64 [[SWITCH_LOAD]] + match input % 4 { + 1 | 2 => 1, + 3 => 2, + _ => 0, + } +} diff --git a/tests/codegen/issues/issue-126585.rs b/tests/codegen/issues/issue-126585.rs new file mode 100644 index 0000000000000..685803dc7a8ce --- /dev/null +++ b/tests/codegen/issues/issue-126585.rs @@ -0,0 +1,23 @@ +//@ compile-flags: -Copt-level=s +//@ min-llvm-version: 19 + +// Test for #126585. +// Ensure that this IR doesn't have extra undef phi input, which also guarantees that this asm +// doesn't have subsequent labels and unnecessary `jmp` instructions. + +#![crate_type = "lib"] + +#[no_mangle] +fn checked_div_round(a: u64, b: u64) -> Option { + // CHECK-LABEL: @checked_div_round + // CHECK: phi + // CHECK-NOT: undef + // CHECK: phi + // CHECK-NOT: undef + match b { + 0 => None, + 1 => Some(a), + // `a / b` is computable and `(a % b) * 2` can not overflow since `b >= 2`. + b => Some(a / b + if (a % b) * 2 >= b { 1 } else { 0 }), + } +}