https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126557
Bug ID: 126557
Summary: [graphite] Different output with -O3
-fgraphite-identity and [[assume]], assumptions
verified by assert build
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: bouncy12578 at gmail dot com
Target Milestone: ---
Created attachment 65200
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65200&action=edit
Preprocessed func.ii file
I observed that enabling -fgraphite-identity changes the output of the attached
C++ testcase, while the same testcase appears to produce the expected output
without that option.
This testcase was generated by a fuzzer and was then reduced.
Compiler Explorer link: https://godbolt.org/z/jsqqTK9a7
The testcase consists of two translation units:
example.cpp
func.cpp
The testcase uses [[assume(x)]] in optimized builds. I also verified the
assumptions by compiling a checking build where ASSUME(x) expands to assert(x).
The checking build was compiled with -Ddebug, so all assumptions were checked
at runtime as assertions. No assertion failed.
The macro used in the testcase is:
#ifndef debug
# define ASSUME(x) [[assume(x)]]
#else
# define ASSUME(x) assert(x)
#endif
GCC version and system information:
Using built-in specs.
COLLECT_GCC=/data/ovolen/compiler-build/gcc/gcc-install/bin/gcc
COLLECT_LTO_WRAPPER=/data/ovolen/compiler-build/gcc/gcc-install/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure
--prefix=/data/ovolen/compiler-build/gcc/gcc-install --disable-bootstrap
--enable-languages=c,c++ --disable-multilib --with-isl --enable-checking=all
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 17.0.0 20260728 (experimental) (GCC)
Command line that triggers the issue:
g++ -O3 -fgraphite-identity example.cpp func.cpp && ./a.out
Actual output:
3152947348269547643
Expected output:
10010287813600298822
The expected output is obtained without -fgraphite-identity:
g++ -O3 example.cpp func.cpp && ./a.out
The expected output is also obtained with the checking build:
g++ -Ddebug -O3 -fsanitize=undefined,address example.cpp func.cpp && ./a.out
No assertion failure and no sanitizer diagnostics were reported.
I also tested with additional options commonly suggested for checking possible
wrong-code reports:
g++ -Ddebug -O3 -Wall -Wextra -fsanitize=undefined,address example.cpp func.cpp
g++ -O3 -fno-strict-aliasing -fwrapv -fgraphite-identity
-fno-aggressive-loop-optimizations example.cpp func.cpp
The issue appears only when -fgraphite-identity is enabled.
Preprocessed files were generated with:
g++ -v -save-temps -O3 -fgraphite-identity -c example.cpp
g++ -v -save-temps -O3 -fgraphite-identity -c func.cpp
g++ -O3 -fgraphite-identity example.o func.o && ./a.out
Attached files:
func.ii (I will attach example.ll later)
Expected behavior:
-fgraphite-identity should not change the observable behavior of the program.
The output should match the build without -fgraphite-identity.
Actual behavior:
With -O3 -fgraphite-identity, GCC produces a different output.