@@ -1911,44 +1911,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
1911
1911
1912
1912
let cast_res = func. new_local ( self . location , dest_ty, "fti_cast_res" ) ;
1913
1913
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) ;
1946
1914
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)
1952
1919
} else {
1953
1920
// Create blocks
1954
1921
let lt_max = func. new_block ( "lt_max" ) ;
@@ -1979,7 +1946,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
1979
1946
self . block . end_with_jump ( self . location , after_block) ;
1980
1947
// The final block - read `cast_res`, continue on our merry way :).
1981
1948
self . switch_to_block ( after_block) ;
1982
- return cast_res. to_rvalue ( ) ;
1949
+ cast_res. to_rvalue ( )
1983
1950
}
1984
1951
}
1985
1952
0 commit comments