9febe9e4be
On top of the previous widening_mul patch, this one recognizes also (non-perfect) signed multiplication with overflow, like: int f5 (int x, int y, int *res) { *res = (unsigned) x * y; return x && (*res / x) != y; } The problem with such checks is that they invoke UB if x is -1 and y is INT_MIN during the division, but perhaps the code knows that those values won't appear. As that case is UB, we can do for that case whatever we want and handling that case as signed overflow is the best option. If x is a constant not equal to -1, then the checks are 100% correct though. Haven't tried to pattern match bullet-proof checks, because I really don't know if users would write it in real-world code like that, perhaps *res = (unsigned) x * y; return x && (x == -1 ? (*res / y) != x : (*res / x) != y); ? https://wiki.sei.cmu.edu/confluence/display/c/INT32-C.+Ensure+that+operations+on+signed+integers+do+not+result+in+overflow suggests to use twice as wide multiplication (perhaps we should handle that too, for both signed and unsigned), or some very large code with 4 different divisions nested in many conditionals, no way one can match all the possible variants thereof. 2021-01-11 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/95852 * tree-ssa-math-opts.c (maybe_optimize_guarding_check): Change mul_stmts parameter type to vec<gimple *> &. Before cond_stmt allow in the bb any of the stmts in that vector, div_stmt and up to 3 cast stmts. (arith_cast_equal_p): New function. (arith_overflow_check_p): Add cast_stmt argument, handle signed multiply overflow checks. (match_arith_overflow): Adjust caller. Handle signed multiply overflow checks. * gcc.target/i386/pr95852-3.c: New test. * gcc.target/i386/pr95852-4.c: New test. |
||
---|---|---|
c++tools | ||
config | ||
contrib | ||
fixincludes | ||
gcc | ||
gnattools | ||
gotools | ||
include | ||
INSTALL | ||
intl | ||
libada | ||
libatomic | ||
libbacktrace | ||
libcc1 | ||
libcody | ||
libcpp | ||
libdecnumber | ||
libffi | ||
libgcc | ||
libgfortran | ||
libgo | ||
libgomp | ||
libhsail-rt | ||
libiberty | ||
libitm | ||
libobjc | ||
liboffloadmic | ||
libphobos | ||
libquadmath | ||
libsanitizer | ||
libssp | ||
libstdc++-v3 | ||
libvtv | ||
lto-plugin | ||
maintainer-scripts | ||
zlib | ||
.dir-locals.el | ||
.gitattributes | ||
.gitignore | ||
ABOUT-NLS | ||
ar-lib | ||
ChangeLog | ||
ChangeLog.jit | ||
ChangeLog.tree-ssa | ||
compile | ||
config-ml.in | ||
config.guess | ||
config.rpath | ||
config.sub | ||
configure | ||
configure.ac | ||
COPYING | ||
COPYING3 | ||
COPYING3.LIB | ||
COPYING.LIB | ||
COPYING.RUNTIME | ||
depcomp | ||
install-sh | ||
libtool-ldflags | ||
libtool.m4 | ||
lt~obsolete.m4 | ||
ltgcc.m4 | ||
ltmain.sh | ||
ltoptions.m4 | ||
ltsugar.m4 | ||
ltversion.m4 | ||
MAINTAINERS | ||
Makefile.def | ||
Makefile.in | ||
Makefile.tpl | ||
missing | ||
mkdep | ||
mkinstalldirs | ||
move-if-change | ||
multilib.am | ||
README | ||
symlink-tree | ||
test-driver | ||
ylwrap |
This directory contains the GNU Compiler Collection (GCC). The GNU Compiler Collection is free software. See the files whose names start with COPYING for copying permission. The manuals, and some of the runtime libraries, are under different terms; see the individual source files for details. The directory INSTALL contains copies of the installation information as HTML and plain text. The source of this information is gcc/doc/install.texi. The installation information includes details of what is included in the GCC sources and what files GCC installs. See the file gcc/doc/gcc.texi (together with other files that it includes) for usage and porting information. An online readable version of the manual is in the files gcc/doc/gcc.info*. See http://gcc.gnu.org/bugs/ for how to report bugs usefully. Copyright years on GCC source files may be listed using range notation, e.g., 1987-2012, indicating that every year in the range, inclusive, is a copyrightable year that could otherwise be listed individually.