Skip to content

Commit 6fe2a60

Browse files
committed
Try only doing the optimization in add
1 parent 0187aef commit 6fe2a60

File tree

1 file changed

+32
-50
lines changed

1 file changed

+32
-50
lines changed

src/builder.rs

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -672,34 +672,28 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
672672
}
673673

674674
fn fadd(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
675-
self.assign_to_var(a + b)
675+
a + b
676676
}
677677

678678
// TODO(antoyo): should we also override the `unchecked_` versions?
679679
fn sub(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
680-
self.assign_to_var(self.gcc_sub(a, b))
680+
self.gcc_sub(a, b)
681681
}
682682

683683
fn fsub(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
684-
self.assign_to_var(a - b)
684+
a - b
685685
}
686686

687687
fn mul(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
688-
self.assign_to_var(self.gcc_mul(a, b))
688+
self.gcc_mul(a, b)
689689
}
690690

691691
fn fmul(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
692-
self.assign_to_var(self.cx.context.new_binary_op(
693-
self.location,
694-
BinaryOp::Mult,
695-
a.get_type(),
696-
a,
697-
b,
698-
))
692+
self.cx.context.new_binary_op(self.location, BinaryOp::Mult, a.get_type(), a, b)
699693
}
700694

701695
fn udiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
702-
self.assign_to_var(self.gcc_udiv(a, b))
696+
self.gcc_udiv(a, b)
703697
}
704698

705699
fn exactudiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
@@ -708,11 +702,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
708702
let a = self.gcc_int_cast(a, a_type);
709703
let b_type = b.get_type().to_unsigned(self);
710704
let b = self.gcc_int_cast(b, b_type);
711-
self.assign_to_var(self.gcc_udiv(a, b))
705+
self.gcc_udiv(a, b)
712706
}
713707

714708
fn sdiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
715-
self.assign_to_var(self.gcc_sdiv(a, b))
709+
self.gcc_sdiv(a, b)
716710
}
717711

718712
fn exactsdiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
@@ -721,19 +715,19 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
721715
// should be the same.
722716
let typ = a.get_type().to_signed(self);
723717
let b = self.gcc_int_cast(b, typ);
724-
self.assign_to_var(self.gcc_sdiv(a, b))
718+
self.gcc_sdiv(a, b)
725719
}
726720

727721
fn fdiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
728-
self.assign_to_var(a / b)
722+
a / b
729723
}
730724

731725
fn urem(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
732-
self.assign_to_var(self.gcc_urem(a, b))
726+
self.gcc_urem(a, b)
733727
}
734728

735729
fn srem(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
736-
self.assign_to_var(self.gcc_srem(a, b))
730+
self.gcc_srem(a, b)
737731
}
738732

739733
fn frem(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
@@ -829,108 +823,96 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
829823
}
830824

831825
fn shl(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
832-
let result = self.gcc_shl(a, b);
833-
self.assign_to_var(result)
826+
self.gcc_shl(a, b)
834827
}
835828

836829
fn lshr(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
837-
let result = self.gcc_lshr(a, b);
838-
self.assign_to_var(result)
830+
self.gcc_lshr(a, b)
839831
}
840832

841833
fn ashr(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
842834
// TODO(antoyo): check whether behavior is an arithmetic shift for >> .
843835
// It seems to be if the value is signed.
844-
let result = self.gcc_lshr(a, b);
845-
self.assign_to_var(result)
836+
self.gcc_lshr(a, b)
846837
}
847838

848839
fn and(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
849-
self.assign_to_var(self.gcc_and(a, b))
840+
self.gcc_and(a, b)
850841
}
851842

852843
fn or(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
853-
self.assign_to_var(self.cx.gcc_or(a, b, self.location))
844+
self.cx.gcc_or(a, b, self.location)
854845
}
855846

856847
fn xor(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
857-
let result = set_rvalue_location(self, self.gcc_xor(a, b));
858-
self.assign_to_var(result)
848+
set_rvalue_location(self, self.gcc_xor(a, b))
859849
}
860850

861851
fn neg(&mut self, a: RValue<'gcc>) -> RValue<'gcc> {
862-
let result = set_rvalue_location(self, self.gcc_neg(a));
863-
self.assign_to_var(result)
852+
set_rvalue_location(self, self.gcc_neg(a))
864853
}
865854

866855
fn fneg(&mut self, a: RValue<'gcc>) -> RValue<'gcc> {
867-
let result = set_rvalue_location(
856+
set_rvalue_location(
868857
self,
869858
self.cx.context.new_unary_op(self.location, UnaryOp::Minus, a.get_type(), a),
870-
);
871-
self.assign_to_var(result)
859+
)
872860
}
873861

874862
fn not(&mut self, a: RValue<'gcc>) -> RValue<'gcc> {
875-
let result = set_rvalue_location(self, self.gcc_not(a));
876-
self.assign_to_var(result)
863+
set_rvalue_location(self, self.gcc_not(a))
877864
}
878865

879866
fn fadd_fast(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
880867
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
881-
let result = set_rvalue_location(self, lhs + rhs);
882-
self.assign_to_var(result)
868+
set_rvalue_location(self, lhs + rhs)
883869
}
884870

885871
fn fsub_fast(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
886872
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
887-
let result = set_rvalue_location(self, lhs - rhs);
888-
self.assign_to_var(result)
873+
set_rvalue_location(self, lhs - rhs)
889874
}
890875

891876
fn fmul_fast(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
892877
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
893-
let result = set_rvalue_location(self, lhs * rhs);
894-
self.assign_to_var(result)
878+
set_rvalue_location(self, lhs * rhs)
895879
}
896880

897881
fn fdiv_fast(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
898882
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
899-
let result = set_rvalue_location(self, lhs / rhs);
900-
self.assign_to_var(result)
883+
set_rvalue_location(self, lhs / rhs)
901884
}
902885

903886
fn frem_fast(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
904887
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
905888
let result = self.frem(lhs, rhs);
906889
set_rvalue_location(self, result);
907-
self.assign_to_var(result)
890+
result
908891
}
909892

910893
fn fadd_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
911894
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
912-
self.assign_to_var(lhs + rhs)
895+
lhs + rhs
913896
}
914897

915898
fn fsub_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
916899
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
917-
self.assign_to_var(lhs - rhs)
900+
lhs - rhs
918901
}
919902

920903
fn fmul_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
921904
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
922-
self.assign_to_var(lhs * rhs)
905+
lhs * rhs
923906
}
924907

925908
fn fdiv_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
926909
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
927-
self.assign_to_var(lhs / rhs)
910+
lhs / rhs
928911
}
929912

930913
fn frem_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
931914
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
932-
let result = self.frem(lhs, rhs);
933-
self.assign_to_var(result)
915+
self.frem(lhs, rhs)
934916
}
935917

936918
fn checked_binop(

0 commit comments

Comments
 (0)