Skip to content

Commit

Permalink
Add codegen tests for issues fixed by LLVM 16
Browse files Browse the repository at this point in the history
Fixes #75978.
Fixes #99960.
Fixes #101048.
Fixes #101082.
Fixes #101814.
Fixes #103132.
Fixes #103327.
  • Loading branch information
nikic committed Apr 3, 2023
1 parent 932c173 commit 73f40d4
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/codegen/issues/issue-101048.rs
Original file line number Diff line number Diff line change
@@ -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))
}
16 changes: 16 additions & 0 deletions tests/codegen/issues/issue-101082.rs
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions tests/codegen/issues/issue-101814.rs
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 16 additions & 0 deletions tests/codegen/issues/issue-103132.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
18 changes: 18 additions & 0 deletions tests/codegen/issues/issue-103327.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
19 changes: 19 additions & 0 deletions tests/codegen/issues/issue-75978.rs
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions tests/codegen/issues/issue-99960.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// compile-flags: -O
// min-llvm-version: 16

#![crate_type = "lib"]

#[no_mangle]
pub fn test(dividend: i64, divisor: i64) -> Option<i64> {
// CHECK-LABEL: @test(
// CHECK-NOT: panic
if dividend > i64::min_value() && divisor != 0 {
Some(dividend / divisor)
} else {
None
}
}

0 comments on commit 73f40d4

Please sign in to comment.