aboutsummaryrefslogtreecommitdiffstats
path: root/powerpc/ConstpropOp.vp
diff options
context:
space:
mode:
authorMichael Schmidt <github@mschmidt.me>2017-12-05 14:48:18 +0100
committerXavier Leroy <xavierleroy@users.noreply.github.com>2017-12-05 14:48:18 +0100
commit90b76a0842b7f080893dd70a7c0c6bc878f4056b (patch)
tree277edd1eecf7bc7574a4b4dc3b925e3479dab8fd /powerpc/ConstpropOp.vp
parent442e82e6ffc6958192f73382d2270e926ead9c80 (diff)
downloadcompcert-kvx-90b76a0842b7f080893dd70a7c0c6bc878f4056b.tar.gz
compcert-kvx-90b76a0842b7f080893dd70a7c0c6bc878f4056b.zip
Optimization for division by one during constant propagation (#39)
Signed and unsigned divisions by literal 1 are already optimized away during the Selection phase. This pull request also optimizes those divisions when the 1 divisor is produced by constant propagation.
Diffstat (limited to 'powerpc/ConstpropOp.vp')
-rw-r--r--powerpc/ConstpropOp.vp15
1 files changed, 9 insertions, 6 deletions
diff --git a/powerpc/ConstpropOp.vp b/powerpc/ConstpropOp.vp
index 0ed92e90..f18a72e9 100644
--- a/powerpc/ConstpropOp.vp
+++ b/powerpc/ConstpropOp.vp
@@ -124,12 +124,15 @@ Definition make_mulimm (n: int) (r1 r2: reg) :=
end.
Definition make_divimm (n: int) (r1 r2: reg) :=
- match Int.is_power2 n with
- | Some l => if Int.ltu l (Int.repr 31)
- then (Oshrximm l, r1 :: nil)
- else (Odiv, r1 :: r2 :: nil)
- | None => (Odiv, r1 :: r2 :: nil)
- end.
+ if Int.eq n Int.one then
+ (Omove, r1 :: nil)
+ else
+ match Int.is_power2 n with
+ | Some l => if Int.ltu l (Int.repr 31)
+ then (Oshrximm l, r1 :: nil)
+ else (Odiv, r1 :: r2 :: nil)
+ | None => (Odiv, r1 :: r2 :: nil)
+ end.
Definition make_divuimm (n: int) (r1 r2: reg) :=
match Int.is_power2 n with