1
Fork 0

Merge commit '1411a98352' into sync_cg_clif-2021-12-31

This commit is contained in:
bjorn3 2021-12-31 16:26:32 +01:00
commit b799d6e0a5
18 changed files with 245 additions and 209 deletions

View file

@ -526,7 +526,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let value =
if result_type.is_signed(self.cx) {
self.context.new_bitcast(None, value, typ)
self.context.new_cast(None, value, typ)
}
else {
value
@ -690,7 +690,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
},
};
self.context.new_bitcast(None, result, result_type)
self.context.new_cast(None, result, result_type)
}
fn count_leading_zeroes(&self, width: u64, arg: RValue<'gcc>) -> RValue<'gcc> {
@ -741,6 +741,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let not_low = self.context.new_unary_op(None, UnaryOp::LogicalNegate, self.u64_type, low);
let not_low_and_not_high = not_low & not_high;
let index = not_high + not_low_and_not_high;
// NOTE: the following cast is necessary to avoid a GIMPLE verification failure in
// gcc.
// TODO(antoyo): do the correct verification in libgccjit to avoid an error at the
// compilation stage.
let index = self.context.new_cast(None, index, self.i32_type);
let res = self.context.new_array_access(None, result, index);
@ -764,7 +769,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let arg =
if result_type.is_signed(self.cx) {
let new_type = result_type.to_unsigned(self.cx);
self.context.new_bitcast(None, arg, new_type)
self.context.new_cast(None, arg, new_type)
}
else {
arg
@ -816,10 +821,15 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let not_high = self.context.new_unary_op(None, UnaryOp::LogicalNegate, self.u64_type, high);
let not_low_and_not_high = not_low & not_high;
let index = not_low + not_low_and_not_high;
// NOTE: the following cast is necessary to avoid a GIMPLE verification failure in
// gcc.
// TODO(antoyo): do the correct verification in libgccjit to avoid an error at the
// compilation stage.
let index = self.context.new_cast(None, index, self.i32_type);
let res = self.context.new_array_access(None, result, index);
return self.context.new_bitcast(None, res, result_type);
return self.context.new_cast(None, res, result_type);
}
else {
unimplemented!("count_trailing_zeroes for {:?}", arg_type);
@ -833,7 +843,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
arg
};
let res = self.context.new_call(None, count_trailing_zeroes, &[arg]);
self.context.new_bitcast(None, res, result_type)
self.context.new_cast(None, res, result_type)
}
fn int_width(&self, typ: Type<'gcc>) -> i64 {
@ -847,7 +857,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let value =
if result_type.is_signed(self.cx) {
self.context.new_bitcast(None, value, value_type)
self.context.new_cast(None, value, value_type)
}
else {
value
@ -863,7 +873,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let low = self.context.new_cast(None, value, self.cx.ulonglong_type);
let low = self.context.new_call(None, popcount, &[low]);
let res = high + low;
return self.context.new_bitcast(None, res, result_type);
return self.context.new_cast(None, res, result_type);
}
// First step.
@ -888,7 +898,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let value = left + right;
if value_type.is_u8(&self.cx) {
return self.context.new_bitcast(None, value, result_type);
return self.context.new_cast(None, value, result_type);
}
// Fourth step.
@ -899,7 +909,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let value = left + right;
if value_type.is_u16(&self.cx) {
return self.context.new_bitcast(None, value, result_type);
return self.context.new_cast(None, value, result_type);
}
// Fifth step.
@ -910,7 +920,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let value = left + right;
if value_type.is_u32(&self.cx) {
return self.context.new_bitcast(None, value, result_type);
return self.context.new_cast(None, value, result_type);
}
// Sixth step.
@ -920,7 +930,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let right = shifted & mask;
let value = left + right;
self.context.new_bitcast(None, value, result_type)
self.context.new_cast(None, value, result_type)
}
// Algorithm from: https://blog.regehr.org/archives/1063