[Bug middle-end/94035] New: Wrong optimization: conditional equivalence vs. values with several representations
ch3root at openwall dot com
gcc-bugzilla@gcc.gnu.org
Wed Mar 4 17:46:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94035
Bug ID: 94035
Summary: Wrong optimization: conditional equivalence vs. values
with several representations
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: ch3root at openwall dot com
Target Milestone: ---
The problem happens when:
- conditional equivalence propagation replaces an expression with a variable or
a constant that has the same value but a different representation, and
- this happens in a computation where representation is accessed.
Example with a pseudo-denormal in long double:
----------------------------------------------------------------------
#include <stdio.h>
__attribute__((noipa,optnone)) // imagine it in a separate TU
static void *opaque(void *p) { return p; }
int main()
{
long double x, y;
unsigned char *px = (unsigned char *)&x;
unsigned char *py = (unsigned char *)&y;
// make x pseudo-denormal
x = 0;
px[7] = 0x80;
opaque(&x); // hide it from the optimizer
y = x;
if (y == 0x1p-16382l)
printf("py[8] = %d\n", py[8]);
printf("py[8] = %d\n", py[8]);
}
----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra -Wno-attributes -O3 test.c && ./a.out
py[8] = 1
py[8] = 0
----------------------------------------------------------------------
gcc x86-64 version: gcc (GCC) 10.0.1 20200304 (experimental)
----------------------------------------------------------------------
The value 0x1p-16382l admits two representations:
00 00 80 00 00 00 00 00 00 00 pseudo-denormal
00 01 80 00 00 00 00 00 00 00 normalized value
So both 0 and 1 for py[8] are fine but the testcase should print the same value
both times, i.e. the representation of y should be stable.
DR 260 Q1 allows for unstable representation but IMO this is wrong.
More information about the Gcc-bugs
mailing list