Simplify X * C1 == C2 with wrapping overflow
authorMarc Glisse <marc.glisse@inria.fr>
Mon, 10 Aug 2020 10:50:42 +0000 (12:50 +0200)
committerMarc Glisse <marc.glisse@inria.fr>
Mon, 10 Aug 2020 10:53:01 +0000 (12:53 +0200)
commit287522613d661b4c5ba8403b051eb470c1674cba
treef9c3ea8dfe1d1a8e89a20f898746d93f96a9de4d
parent9939be5758b52ed2fe1a7e56b94ce6d0f4d81580
Simplify X * C1 == C2 with wrapping overflow

Odd numbers are invertible in Z / 2^n Z, so X * C1 == C2 can be rewritten
as X == C2 * inv(C1) when overflow wraps.

mod_inv should probably be updated to better match the other wide_int
functions, but that's a separate issue.

2020-08-10  Marc Glisse  <marc.glisse@inria.fr>

PR tree-optimization/95433
* match.pd (X * C1 == C2): Handle wrapping overflow.
* expr.c (maybe_optimize_mod_cmp): Qualify call to mod_inv.
(mod_inv): Move...
* wide-int.cc (mod_inv): ... here.
* wide-int.h (mod_inv): Declare it.

* gcc.dg/tree-ssa/pr95433-2.c: New file.
gcc/expr.c
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/pr95433-2.c [new file with mode: 0644]
gcc/wide-int.cc
gcc/wide-int.h