Skip to content

Commit 0fb98e4

Browse files
committed
Small changes
1 parent a406585 commit 0fb98e4

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

src/builder.rs

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,44 +1911,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
19111911

19121912
let cast_res = func.new_local(self.location, dest_ty, "fti_cast_res");
19131913
if signed {
1914-
// Create blocks
1915-
let nan = func.new_block("nan");
1916-
let not_nan = func.new_block("not_nan");
1917-
let gt_min = func.new_block("gt_min");
1918-
let in_bounds = func.new_block("in_bounds");
1919-
let gt_max = func.new_block("gt_max");
1920-
let lt_min = func.new_block("lt_min");
1921-
let after_block = func.new_block("after_cast");
1922-
// First, we check if the value is NAN. If it is, we jump away to the NaN block.
1923-
// If it is not, we continue on to the notNAN block
1924-
let is_nan = self.fcmp(RealPredicate::RealOEQ, val, val);
1925-
self.block.end_with_conditional(self.location, is_nan, nan, not_nan);
1926-
// If the value is NaN, assign 0 to cast_res, and jump to `after`.
1927-
self.switch_to_block(nan);
1928-
self.block.add_assignment(self.location, cast_res, zero);
1929-
self.block.end_with_jump(self.location, after_block);
1930-
// The value is not NaN. Check if it is lower than the min end of our range.
1931-
self.switch_to_block(not_nan);
1932-
self.block.end_with_conditional(self.location, less_or_nan, lt_min, gt_min);
1933-
// Value less than min - assign min to cast_res, jump to `after`.
1934-
self.switch_to_block(lt_min);
1935-
self.block.add_assignment(self.location, cast_res, int_min);
1936-
self.block.end_with_jump(self.location, after_block);
1937-
// Value greater than min - check if it fits within the upper end of our range.
1938-
self.switch_to_block(gt_min);
1939-
self.block.end_with_conditional(self.location, greater, gt_max, in_bounds);
1940-
// Value is greater than MAX - assign MAX to cast_res, jump to after.
1941-
self.switch_to_block(gt_max);
1942-
self.block.add_assignment(self.location, cast_res, int_max);
1943-
self.block.end_with_jump(self.location, after_block);
1944-
// Value in range - we can safely cast.
1945-
self.switch_to_block(in_bounds);
19461914
let fptosi_result = self.fptosi(val, dest_ty);
1947-
self.block.add_assignment(self.location, cast_res, fptosi_result);
1948-
self.block.end_with_jump(self.location, after_block);
1949-
// The final block - read `cast_res`, continue on our merry way :).
1950-
self.switch_to_block(after_block);
1951-
return cast_res.to_rvalue();
1915+
let s0 = self.select(less_or_nan, int_min, fptosi_result);
1916+
let s1 = self.select(greater, int_max, s0);
1917+
let cmp = self.fcmp(RealPredicate::RealOEQ, val, val);
1918+
self.select(cmp, s1, zero)
19521919
} else {
19531920
// Create blocks
19541921
let lt_max = func.new_block("lt_max");

0 commit comments

Comments
 (0)