@@ -501,13 +501,30 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
501
501
intrinsic_args ! ( fx, args => ( c_in, a, b) ; intrinsic) ;
502
502
let c_in = c_in. load_scalar ( fx) ;
503
503
504
- llvm_add_sub ( fx, BinOp :: Add , ret, c_in, a, b) ;
504
+ let ( cb_out, c) = llvm_add_sub ( fx, BinOp :: Add , c_in, a, b) ;
505
+
506
+ let layout = fx. layout_of ( fx. tcx . mk_tup ( & [ fx. tcx . types . u8 , a. layout ( ) . ty ] ) ) ;
507
+ let val = CValue :: by_val_pair ( cb_out, c, layout) ;
508
+ ret. write_cvalue ( fx, val) ;
509
+ }
510
+ "llvm.x86.addcarryx.u32" | "llvm.x86.addcarryx.u64" => {
511
+ intrinsic_args ! ( fx, args => ( c_in, a, b, out) ; intrinsic) ;
512
+ let c_in = c_in. load_scalar ( fx) ;
513
+
514
+ let ( cb_out, c) = llvm_add_sub ( fx, BinOp :: Add , c_in, a, b) ;
515
+
516
+ Pointer :: new ( out. load_scalar ( fx) ) . store ( fx, c, MemFlags :: trusted ( ) ) ;
517
+ ret. write_cvalue ( fx, CValue :: by_val ( cb_out, fx. layout_of ( fx. tcx . types . u8 ) ) ) ;
505
518
}
506
519
"llvm.x86.subborrow.32" | "llvm.x86.subborrow.64" => {
507
520
intrinsic_args ! ( fx, args => ( b_in, a, b) ; intrinsic) ;
508
521
let b_in = b_in. load_scalar ( fx) ;
509
522
510
- llvm_add_sub ( fx, BinOp :: Sub , ret, b_in, a, b) ;
523
+ let ( cb_out, c) = llvm_add_sub ( fx, BinOp :: Sub , b_in, a, b) ;
524
+
525
+ let layout = fx. layout_of ( fx. tcx . mk_tup ( & [ fx. tcx . types . u8 , a. layout ( ) . ty ] ) ) ;
526
+ let val = CValue :: by_val_pair ( cb_out, c, layout) ;
527
+ ret. write_cvalue ( fx, val) ;
511
528
}
512
529
_ => {
513
530
fx. tcx
@@ -532,11 +549,10 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
532
549
fn llvm_add_sub < ' tcx > (
533
550
fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
534
551
bin_op : BinOp ,
535
- ret : CPlace < ' tcx > ,
536
552
cb_in : Value ,
537
553
a : CValue < ' tcx > ,
538
554
b : CValue < ' tcx > ,
539
- ) {
555
+ ) -> ( Value , Value ) {
540
556
assert_eq ! ( a. layout( ) . ty, b. layout( ) . ty) ;
541
557
542
558
// c + carry -> c + first intermediate carry or borrow respectively
@@ -554,7 +570,5 @@ fn llvm_add_sub<'tcx>(
554
570
// carry0 | carry1 -> carry or borrow respectively
555
571
let cb_out = fx. bcx . ins ( ) . bor ( cb0, cb1) ;
556
572
557
- let layout = fx. layout_of ( fx. tcx . mk_tup ( & [ fx. tcx . types . u8 , a. layout ( ) . ty ] ) ) ;
558
- let val = CValue :: by_val_pair ( cb_out, c, layout) ;
559
- ret. write_cvalue ( fx, val) ;
573
+ ( cb_out, c)
560
574
}
0 commit comments