]> git.lizzy.rs Git - rust.git/commitdiff
Workaround for missing select.i8 encoding
authorbjorn3 <bjorn3@users.noreply.github.com>
Sun, 7 Oct 2018 09:18:08 +0000 (11:18 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Sun, 7 Oct 2018 09:31:42 +0000 (11:31 +0200)
src/common.rs
src/intrinsics.rs

index fb030470936a4786bd18970dd72ae176c042bd83..54c393e2824fe00823fa2d508534448f9ce640d4 100644 (file)
@@ -69,6 +69,21 @@ pub fn cton_type_from_ty<'a, 'tcx: 'a>(
     })
 }
 
+pub fn codegen_select(bcx: &mut FunctionBuilder, cond: Value, lhs: Value, rhs: Value) -> Value {
+    let lhs_ty = bcx.func.dfg.value_type(lhs);
+    let rhs_ty = bcx.func.dfg.value_type(rhs);
+    assert_eq!(lhs_ty, rhs_ty);
+    if lhs_ty == types::I8 || lhs_ty == types::I16 {
+        // FIXME workaround for missing enocding for select.i8
+        let lhs = bcx.ins().uextend(types::I32, lhs);
+        let rhs = bcx.ins().uextend(types::I32, rhs);
+        let res = bcx.ins().select(cond, lhs, rhs);
+        bcx.ins().ireduce(lhs_ty, res)
+    } else {
+        bcx.ins().select(cond, lhs, rhs)
+    }
+}
+
 fn codegen_field<'a, 'tcx: 'a>(
     fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
     base: Value,
index 1cc16419413cc18e8ee4ee4c4fef26371d8b7c56..79ed21ce3112ee7c2d9fd3c5ee2d8d2e44c40e50 100644 (file)
@@ -76,7 +76,7 @@ macro_rules! atomic_minmax {
 
         // Compare
         let is_eq = $fx.bcx.ins().icmp(IntCC::SignedGreaterThan, old, $src);
-        let new = $fx.bcx.ins().select(is_eq, old, $src);
+        let new = crate::common::codegen_select(&mut $fx.bcx, is_eq, old, $src);
 
         // Write new
         $fx.bcx.ins().store(MemFlags::new(), new, $ptr, 0);
@@ -378,7 +378,7 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
 
             // Compare
             let is_eq = fx.bcx.ins().icmp(IntCC::Equal, old, test_old);
-            let new = fx.bcx.ins().select(is_eq, old, new); // Keep old if not equal to test_old
+            let new = crate::common::codegen_select(&mut fx.bcx, is_eq, old, new); // Keep old if not equal to test_old
 
             // Write new
             fx.bcx.ins().store(MemFlags::new(), new, ptr, 0);