@@ -728,49 +728,45 @@ pub fn invoke<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
728
728
}
729
729
}
730
730
731
- if need_invoke ( bcx) {
731
+ let ( mut llresult , bcx ) = if need_invoke ( bcx) {
732
732
debug ! ( "invoking {} at {:?}" , bcx. val_to_string( llfn) , bcx. llbb) ;
733
733
for & llarg in llargs {
734
734
debug ! ( "arg: {}" , bcx. val_to_string( llarg) ) ;
735
735
}
736
736
let normal_bcx = bcx. fcx . new_temp_block ( "normal-return" ) ;
737
737
let landing_pad = bcx. fcx . get_landing_pad ( ) ;
738
738
739
- let mut llresult = Invoke ( bcx,
739
+ let llresult = Invoke ( bcx,
740
740
llfn,
741
741
& llargs[ ..] ,
742
742
normal_bcx. llbb ,
743
743
landing_pad,
744
744
Some ( attributes) ,
745
745
debug_loc) ;
746
- if let ty:: FnConverging ( ty) = ret_ty {
747
- if return_type_is_void ( bcx. ccx ( ) , ty) {
748
- llresult = C_nil ( bcx. ccx ( ) ) ;
749
- }
750
- } else {
751
- llresult = C_nil ( bcx. ccx ( ) ) ;
752
- }
753
- return ( llresult, normal_bcx) ;
746
+ ( llresult, normal_bcx)
754
747
} else {
755
748
debug ! ( "calling {} at {:?}" , bcx. val_to_string( llfn) , bcx. llbb) ;
756
749
for & llarg in llargs {
757
750
debug ! ( "arg: {}" , bcx. val_to_string( llarg) ) ;
758
751
}
759
752
760
- let mut llresult = Call ( bcx,
753
+ let llresult = Call ( bcx,
761
754
llfn,
762
755
& llargs[ ..] ,
763
756
Some ( attributes) ,
764
757
debug_loc) ;
765
- if let ty :: FnConverging ( ty ) = ret_ty {
766
- if return_type_is_void ( bcx . ccx ( ) , ty ) {
767
- llresult = C_nil ( bcx . ccx ( ) ) ;
768
- }
769
- } else {
758
+ ( llresult , bcx )
759
+ } ;
760
+
761
+ if let ty :: FnConverging ( ty ) = ret_ty {
762
+ if return_type_is_void ( bcx . ccx ( ) , ty ) {
770
763
llresult = C_nil ( bcx. ccx ( ) ) ;
771
764
}
772
- return ( llresult, bcx) ;
765
+ } else {
766
+ llresult = C_nil ( bcx. ccx ( ) ) ;
773
767
}
768
+
769
+ ( llresult, bcx)
774
770
}
775
771
776
772
pub fn need_invoke ( bcx : Block ) -> bool {
@@ -803,41 +799,30 @@ pub fn load_if_immediate<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
803
799
/// gives us better information about what we are loading.
804
800
pub fn load_ty < ' blk , ' tcx > ( cx : Block < ' blk , ' tcx > ,
805
801
ptr : ValueRef , t : Ty < ' tcx > ) -> ValueRef {
806
- use trans:: basic_block:: BasicBlock ;
807
-
808
802
if cx. unreachable . get ( ) || type_is_zero_size ( cx. ccx ( ) , t) {
809
803
return C_undef ( type_of:: type_of ( cx. ccx ( ) , t) ) ;
810
804
}
811
805
812
806
let ptr = to_arg_ty_ptr ( cx, ptr, t) ;
813
- let ptr = Value ( ptr) ;
814
807
let align = type_of:: align_of ( cx. ccx ( ) , t) ;
815
808
816
- let bb = BasicBlock ( cx. llbb ) ;
817
-
818
809
if type_is_immediate ( cx. ccx ( ) , t) && type_of:: type_of ( cx. ccx ( ) , t) . is_aggregate ( ) {
819
- if let Some ( val) = ptr. get_dominating_store ( cx) {
820
- let valbb = val. get_parent ( ) ;
821
-
822
- if Some ( bb) == valbb {
823
- if let Some ( val) = val. get_operand ( 0 ) {
824
- debug ! ( "Eliding load from {}" , cx. ccx( ) . tn( ) . val_to_string( ptr. get( ) ) ) ;
825
- debug ! ( " Using previous stored value: {}" ,
826
- cx. ccx( ) . tn( ) . val_to_string( val. get( ) ) ) ;
827
- return val. get ( ) ;
828
- }
829
- }
810
+ if let Some ( val) = Value ( ptr) . get_stored_value_opt ( cx) {
811
+ debug ! ( "Eliding load from {}" , cx. ccx( ) . tn( ) . val_to_string( ptr) ) ;
812
+ debug ! ( " Using previous stored value: {}" ,
813
+ cx. ccx( ) . tn( ) . val_to_string( val. get( ) ) ) ;
814
+ return val. get ( ) ;
830
815
}
831
816
832
- let load = Load ( cx, ptr. get ( ) ) ;
817
+ let load = Load ( cx, ptr) ;
833
818
unsafe {
834
819
llvm:: LLVMSetAlignment ( load, align) ;
835
820
}
836
821
return load;
837
822
}
838
823
839
824
unsafe {
840
- let global = llvm:: LLVMIsAGlobalVariable ( ptr. get ( ) ) ;
825
+ let global = llvm:: LLVMIsAGlobalVariable ( ptr) ;
841
826
if !global. is_null ( ) && llvm:: LLVMIsGlobalConstant ( global) == llvm:: True {
842
827
let val = llvm:: LLVMGetInitializer ( global) ;
843
828
if !val. is_null ( ) {
@@ -846,30 +831,24 @@ pub fn load_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
846
831
}
847
832
}
848
833
849
- if let Some ( val) = ptr. get_dominating_store ( cx) {
850
- let valbb = val. get_parent ( ) ;
851
-
852
- if Some ( bb) == valbb {
853
- if let Some ( val) = val. get_operand ( 0 ) {
854
- debug ! ( "Eliding load from {}" , cx. ccx( ) . tn( ) . val_to_string( ptr. get( ) ) ) ;
855
- debug ! ( " Using previous stored value: {}" ,
856
- cx. ccx( ) . tn( ) . val_to_string( val. get( ) ) ) ;
857
- return to_arg_ty ( cx, val. get ( ) , t) ;
858
- }
859
- }
834
+ if let Some ( val) = Value ( ptr) . get_stored_value_opt ( cx) {
835
+ debug ! ( "Eliding load from {}" , cx. ccx( ) . tn( ) . val_to_string( ptr) ) ;
836
+ debug ! ( " Using previous stored value: {}" ,
837
+ cx. ccx( ) . tn( ) . val_to_string( val. get( ) ) ) ;
838
+ return to_arg_ty ( cx, val. get ( ) , t) ;
860
839
}
861
840
862
841
let val = if t. is_bool ( ) {
863
- LoadRangeAssert ( cx, ptr. get ( ) , 0 , 2 , llvm:: False )
842
+ LoadRangeAssert ( cx, ptr, 0 , 2 , llvm:: False )
864
843
} else if t. is_char ( ) {
865
844
// a char is a Unicode codepoint, and so takes values from 0
866
845
// to 0x10FFFF inclusive only.
867
- LoadRangeAssert ( cx, ptr. get ( ) , 0 , 0x10FFFF + 1 , llvm:: False )
846
+ LoadRangeAssert ( cx, ptr, 0 , 0x10FFFF + 1 , llvm:: False )
868
847
} else if ( t. is_region_ptr ( ) || t. is_unique ( ) )
869
848
&& !common:: type_is_fat_ptr ( cx. tcx ( ) , t) {
870
- LoadNonNull ( cx, ptr. get ( ) )
849
+ LoadNonNull ( cx, ptr)
871
850
} else {
872
- Load ( cx, ptr. get ( ) )
851
+ Load ( cx, ptr)
873
852
} ;
874
853
875
854
unsafe {
@@ -918,11 +897,16 @@ pub fn from_arg_ty(bcx: Block, val: ValueRef, ty: Ty) -> ValueRef {
918
897
919
898
pub fn to_arg_ty ( bcx : Block , val : ValueRef , ty : Ty ) -> ValueRef {
920
899
if ty. is_bool ( ) {
900
+ // Look for cases where we're truncating a zext from a bool already and grab the original
901
+ // value. This can happen with an elided load from a boolean location. While this can be
902
+ // easily optimized out, the indirection can interfere with some intrinsics.
921
903
let val = Value ( val) ;
922
904
if let Some ( zext) = val. as_zext_inst ( ) {
905
+ // `val` == zext %foo
923
906
if let Some ( val) = zext. get_operand ( 0 ) {
924
907
let valty = val_ty ( val. get ( ) ) ;
925
908
if valty == Type :: i1 ( bcx. ccx ( ) ) {
909
+ // %foo : i1
926
910
return val. get ( ) ;
927
911
}
928
912
}
0 commit comments