From 92fc8a425034abc1247203a4c0d471e8b6d0e941 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Wed, 5 Jul 2017 12:20:18 +0200 Subject: Issue #16P: wrong rlwinm instruction generated by constant propagation This happens when the divisor of an unsigned int32 division is constant-propagated to 1. --- powerpc/ConstpropOp.vp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'powerpc/ConstpropOp.vp') diff --git a/powerpc/ConstpropOp.vp b/powerpc/ConstpropOp.vp index 8946ae27..886655a0 100644 --- a/powerpc/ConstpropOp.vp +++ b/powerpc/ConstpropOp.vp @@ -92,11 +92,15 @@ Definition make_shrimm (n: int) (r1 r2: reg) := else (Oshr, r1 :: r2 :: nil). -Definition make_shruimm (n: int) (r1 r2: reg) := +Definition make_shruimm_aux (n: int) (r1: reg) := if Int.eq n Int.zero then (Omove, r1 :: nil) - else if Int.ltu n Int.iwordsize then - (Orolm (Int.sub Int.iwordsize n) (Int.shru Int.mone n), r1 :: nil) + else + (Orolm (Int.sub Int.iwordsize n) (Int.shru Int.mone n), r1 :: nil). + +Definition make_shruimm (n: int) (r1 r2: reg) := + if Int.ltu n Int.iwordsize then + make_shruimm_aux n r1 else (Oshru, r1 :: r2 :: nil). @@ -121,7 +125,7 @@ Definition make_divimm (n: int) (r1 r2: reg) := Definition make_divuimm (n: int) (r1 r2: reg) := match Int.is_power2 n with - | Some l => (Orolm (Int.sub Int.iwordsize l) (Int.shru Int.mone l), r1 :: nil) + | Some l => make_shruimm_aux l r1 | None => (Odivu, r1 :: r2 :: nil) end. -- cgit