[bugpoint] Convert more types to constants

This commit is contained in:
teapotd
2020-05-29 04:33:34 +02:00
committed by Andrew Brown
parent e0d7f1a91b
commit b3763223ab
3 changed files with 70 additions and 11 deletions

View File

@@ -762,10 +762,7 @@ impl Mutator for MergeBlocks {
}
}
fn const_for_type<'f, T: InstBuilder<'f>>(builder: T, ty: ir::Type) -> &'static str {
// Try to keep the result type consistent, and default to an integer type
// otherwise: this will cover all the cases for f32/f64, integer and boolean types,
// or create verifier errors otherwise.
fn const_for_type<'f, T: InstBuilder<'f>>(mut builder: T, ty: ir::Type) -> &'static str {
if ty == F32 {
builder.f32const(0.0);
"f32const"
@@ -775,7 +772,16 @@ fn const_for_type<'f, T: InstBuilder<'f>>(builder: T, ty: ir::Type) -> &'static
} else if ty.is_bool() {
builder.bconst(ty, false);
"bconst"
} else if ty.is_ref() {
builder.null(ty);
"null"
} else if ty.is_vector() {
let zero_data = vec![0; ty.bytes() as usize].into();
let zero_handle = builder.data_flow_graph_mut().constants.insert(zero_data);
builder.vconst(ty, zero_handle);
"vconst"
} else {
// Default to an integer type and possibly create verifier error
builder.iconst(ty, 0);
"iconst"
}
@@ -1054,12 +1060,8 @@ mod tests {
use super::*;
use cranelift_reader::ParseOptions;
#[test]
fn test_reduce() {
const TEST: &str = include_str!("../tests/bugpoint_test.clif");
const EXPECTED: &str = include_str!("../tests/bugpoint_test_expected.clif");
let test_file = parse_test(TEST, ParseOptions::default()).unwrap();
fn run_test(test_str: &str, expected_str: &str) {
let test_file = parse_test(test_str, ParseOptions::default()).unwrap();
// If we have an isa from the command-line, use that. Otherwise if the
// file contains a unique isa, use that.
@@ -1085,7 +1087,24 @@ mod tests {
"reduction wasn't maximal for insts"
);
assert_eq!(format!("{}", reduced_func), EXPECTED.replace("\r\n", "\n"));
assert_eq!(
format!("{}", reduced_func),
expected_str.replace("\r\n", "\n")
);
}
}
#[test]
fn test_reduce() {
const TEST: &str = include_str!("../tests/bugpoint_test.clif");
const EXPECTED: &str = include_str!("../tests/bugpoint_test_expected.clif");
run_test(TEST, EXPECTED);
}
#[test]
fn test_consts() {
const TEST: &str = include_str!("../tests/bugpoint_consts.clif");
const EXPECTED: &str = include_str!("../tests/bugpoint_consts_expected.clif");
run_test(TEST, EXPECTED);
}
}

View File

@@ -0,0 +1,14 @@
test compile
target x86_64
function u0:0() {
sig0 = (f32, f64, i8, i16, i32, i64, i128, b1, b8, b128, r32, r64, b8x16, i16x4, f32x16)
fn0 = u0:1 sig0
block0:
trap user0
block1(v0: f32, v1: f64, v2: i8, v3: i16, v4: i32, v5: i64, v6: i128, v7: b1, v8: b8, v9: b128, v10: r32, v11: r64, v12: b8x16, v13: i16x4, v14: f32x16):
call fn0(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)
trap user0
}

View File

@@ -0,0 +1,26 @@
function u0:0() fast {
sig0 = (f32, f64, i8, i16, i32, i64, i128, b1, b8, b128, r32, r64, b8x16, i16x4, f32x16) fast
fn0 = u0:1 sig0
const0 = 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
const1 = 0x0000000000000000
const2 = 0x00000000000000000000000000000000
block1:
v0 = f32const 0.0
v1 = f64const 0.0
v2 = iconst.i8 0
v3 = iconst.i16 0
v4 = iconst.i32 0
v5 = iconst.i64 0
v6 = iconst.i128 0
v7 = bconst.b1 false
v8 = bconst.b8 false
v9 = bconst.b128 false
v10 = null.r32
v11 = null.r64
v12 = vconst.b8x16 const2
v13 = vconst.i16x4 const1
v14 = vconst.f32x16 const0
call fn0(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)
trap user0
}