From 73f40d429317e7c9c87de0cf828d02b0442a25da Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 3 Apr 2023 16:37:42 +0200 Subject: [PATCH 1/3] Add codegen tests for issues fixed by LLVM 16 Fixes #75978. Fixes #99960. Fixes #101048. Fixes #101082. Fixes #101814. Fixes #103132. Fixes #103327. --- tests/codegen/issues/issue-101048.rs | 13 +++++++++++++ tests/codegen/issues/issue-101082.rs | 16 ++++++++++++++++ tests/codegen/issues/issue-101814.rs | 19 +++++++++++++++++++ tests/codegen/issues/issue-103132.rs | 16 ++++++++++++++++ tests/codegen/issues/issue-103327.rs | 18 ++++++++++++++++++ tests/codegen/issues/issue-75978.rs | 19 +++++++++++++++++++ tests/codegen/issues/issue-99960.rs | 15 +++++++++++++++ 7 files changed, 116 insertions(+) create mode 100644 tests/codegen/issues/issue-101048.rs create mode 100644 tests/codegen/issues/issue-101082.rs create mode 100644 tests/codegen/issues/issue-101814.rs create mode 100644 tests/codegen/issues/issue-103132.rs create mode 100644 tests/codegen/issues/issue-103327.rs create mode 100644 tests/codegen/issues/issue-75978.rs create mode 100644 tests/codegen/issues/issue-99960.rs diff --git a/tests/codegen/issues/issue-101048.rs b/tests/codegen/issues/issue-101048.rs new file mode 100644 index 000000000000..efa4db93ec21 --- /dev/null +++ b/tests/codegen/issues/issue-101048.rs @@ -0,0 +1,13 @@ +// compile-flags: -O +// min-llvm-version: 16 + +#![crate_type = "lib"] + +#[no_mangle] +pub fn all_zero(data: &[u64]) -> bool { + // CHECK-LABEL: @all_zero( + // CHECK: [[PHI:%.*]] = phi i1 + // CHECK-NOT: phi i8 + // CHECK-NOT: zext + data.iter().copied().fold(true, |acc, x| acc & (x == 0)) +} diff --git a/tests/codegen/issues/issue-101082.rs b/tests/codegen/issues/issue-101082.rs new file mode 100644 index 000000000000..effe8f4a60e3 --- /dev/null +++ b/tests/codegen/issues/issue-101082.rs @@ -0,0 +1,16 @@ +// compile-flags: -O +// min-llvm-version: 16 + +#![crate_type = "lib"] + +#[no_mangle] +pub fn test() -> usize { + // CHECK-LABEL: @test( + // CHECK: ret i64 165 + let values = [23, 16, 54, 3, 60, 9]; + let mut acc = 0; + for item in values { + acc += item; + } + acc +} diff --git a/tests/codegen/issues/issue-101814.rs b/tests/codegen/issues/issue-101814.rs new file mode 100644 index 000000000000..4e4745ed633d --- /dev/null +++ b/tests/codegen/issues/issue-101814.rs @@ -0,0 +1,19 @@ +// compile-flags: -O +// min-llvm-version: 16 + +#![crate_type = "lib"] + +#[no_mangle] +pub fn test(a: [i32; 10]) -> i32 { + // CHECK-LABEL: @test( + // CHECK: [[L1:%.+]] = load i32 + // CHECK: [[L2:%.+]] = load i32 + // CHECK: [[R:%.+]] = add i32 [[L1]], [[L2]] + // CHECK: ret i32 [[R]] + let mut sum = 0; + for v in a.iter().skip(8) { + sum += v; + } + + sum +} diff --git a/tests/codegen/issues/issue-103132.rs b/tests/codegen/issues/issue-103132.rs new file mode 100644 index 000000000000..cc87d7cd2b9d --- /dev/null +++ b/tests/codegen/issues/issue-103132.rs @@ -0,0 +1,16 @@ +// compile-flags: -O -C overflow-checks +// min-llvm-version: 16 + +#![crate_type = "lib"] + +#[no_mangle] +pub fn test(arr: &[u8], weight: u32) { + // CHECK-LABEL: @test( + // CHECK-NOT: panic + let weight = weight.min(256 * 256 * 256); + + for x in arr { + assert!(weight <= 256 * 256 * 256); + let result = *x as u32 * weight; + } +} diff --git a/tests/codegen/issues/issue-103327.rs b/tests/codegen/issues/issue-103327.rs new file mode 100644 index 000000000000..cee00faccc81 --- /dev/null +++ b/tests/codegen/issues/issue-103327.rs @@ -0,0 +1,18 @@ +// compile-flags: -O +// min-llvm-version: 16 + +#![crate_type = "lib"] + +#[no_mangle] +pub fn test(a: i32, b: i32) -> bool { + // CHECK-LABEL: @test( + // CHECK: ret i1 true + let c1 = (a >= 0) && (a <= 10); + let c2 = (b >= 0) && (b <= 20); + + if c1 & c2 { + a + 100 != b + } else { + true + } +} diff --git a/tests/codegen/issues/issue-75978.rs b/tests/codegen/issues/issue-75978.rs new file mode 100644 index 000000000000..f335e92c3dc4 --- /dev/null +++ b/tests/codegen/issues/issue-75978.rs @@ -0,0 +1,19 @@ +// compile-flags: -O +// min-llvm-version: 16 + +#![crate_type = "lib"] + +#[no_mangle] +pub fn test() -> u32 { + // CHECK-LABEL: @test( + // CHECK: ret i32 13 + let s = [1, 2, 3, 4, 5, 6, 7]; + + let mut iter = s.iter(); + let mut sum = 0; + while let Some(_) = iter.next() { + sum += iter.next().map_or(1, |&x| x) + } + + sum +} diff --git a/tests/codegen/issues/issue-99960.rs b/tests/codegen/issues/issue-99960.rs new file mode 100644 index 000000000000..e9c9367fa64b --- /dev/null +++ b/tests/codegen/issues/issue-99960.rs @@ -0,0 +1,15 @@ +// compile-flags: -O +// min-llvm-version: 16 + +#![crate_type = "lib"] + +#[no_mangle] +pub fn test(dividend: i64, divisor: i64) -> Option { + // CHECK-LABEL: @test( + // CHECK-NOT: panic + if dividend > i64::min_value() && divisor != 0 { + Some(dividend / divisor) + } else { + None + } +} From ec635c002b99371c1c45d98df0e5664bdb57a644 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 11 Apr 2023 11:22:15 +0200 Subject: [PATCH 2/3] Add ignore-debug to two tests These don't optimize with debug assertions. For one of them, this is due to the new alignment checks, for the other I'm not sure what specifically blocks it. --- tests/codegen/issues/issue-101082.rs | 1 + tests/codegen/issues/issue-101814.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/codegen/issues/issue-101082.rs b/tests/codegen/issues/issue-101082.rs index effe8f4a60e3..27387d0c1192 100644 --- a/tests/codegen/issues/issue-101082.rs +++ b/tests/codegen/issues/issue-101082.rs @@ -1,5 +1,6 @@ // compile-flags: -O // min-llvm-version: 16 +// ignore-debug: the debug assertions get in the way #![crate_type = "lib"] diff --git a/tests/codegen/issues/issue-101814.rs b/tests/codegen/issues/issue-101814.rs index 4e4745ed633d..13796352c028 100644 --- a/tests/codegen/issues/issue-101814.rs +++ b/tests/codegen/issues/issue-101814.rs @@ -1,5 +1,6 @@ // compile-flags: -O // min-llvm-version: 16 +// ignore-debug: the debug assertions get in the way #![crate_type = "lib"] From 83f525cc2897d3561e268d3ea2207cd49a1c1bff Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 11 Apr 2023 17:19:07 +0200 Subject: [PATCH 3/3] Make test compatible with 32-bit --- tests/codegen/issues/issue-101082.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/codegen/issues/issue-101082.rs b/tests/codegen/issues/issue-101082.rs index 27387d0c1192..2cbe99942cba 100644 --- a/tests/codegen/issues/issue-101082.rs +++ b/tests/codegen/issues/issue-101082.rs @@ -7,7 +7,7 @@ #[no_mangle] pub fn test() -> usize { // CHECK-LABEL: @test( - // CHECK: ret i64 165 + // CHECK: ret {{i64|i32}} 165 let values = [23, 16, 54, 3, 60, 9]; let mut acc = 0; for item in values {