public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3
@ 2024-03-26 4:34 patrick at rivosinc dot com
2024-03-26 5:04 ` [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vector-cost-mode (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv) pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: patrick at rivosinc dot com @ 2024-03-26 4:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114476
Bug ID: 114476
Summary: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: patrick at rivosinc dot com
Target Milestone: ---
Testcase:
signed char b = 9;
int c[23][23];
signed char d[23];
int main() {
for (int h = 0; h < 23; h += 2) {
c[h][h] = d[h];
b *= 255;
}
__builtin_printf("%u\n", b);
}
Commands:
> /scratch/tc-testing/tc-mar-25/build-rv64gcv/bin/riscv64-unknown-linux-gnu-gcc -march=rv64gcv -O3 -fwrapv red.c -o red.out
> /scratch/tc-testing/tc-mar-25/build-rv64gcv/bin/qemu-riscv64 red.out
4294967287
> /scratch/tc-testing/tc-mar-25/build-rv64gcv/bin/riscv64-unknown-linux-gnu-gcc -march=rv64gcv -O2 -fwrapv red.c -o red.out
> /scratch/tc-testing/tc-mar-25/build-rv64gcv/bin/qemu-riscv64 red.out
9
Discovered/tested using r14-9654-g78b56a12dd0 (not bisected)
Found via fuzzer.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vector-cost-mode (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv)
2024-03-26 4:34 [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3 patrick at rivosinc dot com
@ 2024-03-26 5:04 ` pinskia at gcc dot gnu.org
2024-03-26 5:05 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-26 5:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114476
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-03-26
Component|target |tree-optimization
Ever confirmed|0 |1
Known to fail| |13.2.0
Target|riscv*-*-* |riscv*-*-* aarch64
Keywords| |needs-bisection
Summary|[14] RISC-V rv64gcv vector: |[13/14 Regression] wrong
|Runtime mismatch at -O3 |code with -fwrapv -O3
| |-fno-vector-cost-mode (and
| |-march=armv9-a+sve2 on
| |aarch64 and -march=rv64gcv
| |on riscv)
Status|UNCONFIRMED |NEW
Target Milestone|--- |14.0
Known to work| |12.3.0
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Happens on aarch64 with `-march=armv9-a+sve2 -fno-vect-cost-model` even in GCC
13.2.0.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vector-cost-mode (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv)
2024-03-26 4:34 [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3 patrick at rivosinc dot com
2024-03-26 5:04 ` [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vector-cost-mode (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv) pinskia at gcc dot gnu.org
@ 2024-03-26 5:05 ` pinskia at gcc dot gnu.org
2024-03-26 5:10 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-26 5:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114476
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note -fwrapv is important here ...
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vector-cost-mode (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv)
2024-03-26 4:34 [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3 patrick at rivosinc dot com
2024-03-26 5:04 ` [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vector-cost-mode (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv) pinskia at gcc dot gnu.org
2024-03-26 5:05 ` pinskia at gcc dot gnu.org
@ 2024-03-26 5:10 ` pinskia at gcc dot gnu.org
2024-03-26 5:16 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-26 5:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114476
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a testcase where we don't need -fwrapv:
```
signed int b = 9;
int c[23][23];
signed int d[23];
int main() {
for (int h = 0; h < 23; h += 2) {
c[h][h] = d[h];
b= -b;
}
__builtin_printf("%u\n", b);
}
```
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vector-cost-mode (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv)
2024-03-26 4:34 [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3 patrick at rivosinc dot com
` (2 preceding siblings ...)
2024-03-26 5:10 ` pinskia at gcc dot gnu.org
@ 2024-03-26 5:16 ` pinskia at gcc dot gnu.org
2024-03-26 8:07 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-26 5:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114476
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> Here is a testcase where we don't need -fwrapv:
Ignore that, I was doing something wrong.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vector-cost-mode (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv)
2024-03-26 4:34 [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3 patrick at rivosinc dot com
` (3 preceding siblings ...)
2024-03-26 5:16 ` pinskia at gcc dot gnu.org
@ 2024-03-26 8:07 ` rguenth at gcc dot gnu.org
2024-03-26 12:47 ` rdapp at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-03-26 8:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114476
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|14.0 |13.3
Priority|P3 |P2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vector-cost-mode (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv)
2024-03-26 4:34 [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3 patrick at rivosinc dot com
` (4 preceding siblings ...)
2024-03-26 8:07 ` rguenth at gcc dot gnu.org
@ 2024-03-26 12:47 ` rdapp at gcc dot gnu.org
2024-03-27 21:03 ` [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vect-cost-model " pinskia at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rdapp at gcc dot gnu.org @ 2024-03-26 12:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114476
--- Comment #5 from Robin Dapp <rdapp at gcc dot gnu.org> ---
So the result is -9 instead of 9 (or vice versa) and this happens (just) with
vectorization. We only vectorize with -fwrapv.
From a first quick look, the following is what we have before vect:
(loop)
<bb 3> [local count: 991171080]:
...
# b_lsm.5_5 = PHI <_4(7), b_lsm.5_17(2)>
...
_4 = -b_lsm.5_5;
(check)
<bb 4> [local count: 82570744]:
...
# b_lsm.5_22 = PHI <b_lsm.5_5(3)>
...
if (b_lsm.5_22 != -9)
I.e. b gets negated with every iteration and we check the second to last
against -9.
With vectorization we have:
(init)
<bb 2> [local count: 82570744]:
b_lsm.5_17 = b;
(vectorized loop)
<bb 3> [local count: 247712231]:
...
# b_lsm.5_5 = PHI <_4(7), b_lsm.5_17(2)>
...
_4 = -b_lsm.5_5;
...
goto <bb 3>
(epilogue)
<bb 10> [local count: 82570741]:
...
# b_lsm.5_7 = PHI <_25(11), b_lsm.5_17(13)>
...
_25 = -b_lsm.5_7;
(check)
<bb 4> [local count: 82570744]:
...
# b_lsm.5_22 = PHI <b_lsm.5_7(10)>
if (b_lsm.5_22 != -9)
What looks odd here is that b_lsm.5_7's fallthrough argument is b_lsm.5_17 even
though we must have come through the vectorized loop (which negated b at least
once). This makes us skip inversions.
Indeed, as b_lsm.5_22 is only dependent on the initial value of b it gets
optimized away and we compare b != -9.
Maybe I missed something but it looks like
# b_lsm.5_7 = PHI <_25(11), b_lsm.5_17(13)>
should have b_lsm.5_5 or _4 as fallthrough argument.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vect-cost-model (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv)
2024-03-26 4:34 [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3 patrick at rivosinc dot com
` (5 preceding siblings ...)
2024-03-26 12:47 ` rdapp at gcc dot gnu.org
@ 2024-03-27 21:03 ` pinskia at gcc dot gnu.org
2024-04-03 1:48 ` juzhe.zhong at rivai dot ai
2024-04-03 12:05 ` rdapp at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-27 21:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114476
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am going to mark this as a dup of bug 114485 since the issue is exactly the
same.
*** This bug has been marked as a duplicate of bug 114485 ***
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vect-cost-model (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv)
2024-03-26 4:34 [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3 patrick at rivosinc dot com
` (6 preceding siblings ...)
2024-03-27 21:03 ` [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vect-cost-model " pinskia at gcc dot gnu.org
@ 2024-04-03 1:48 ` juzhe.zhong at rivai dot ai
2024-04-03 12:05 ` rdapp at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: juzhe.zhong at rivai dot ai @ 2024-04-03 1:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114476
--- Comment #7 from JuzheZhong <juzhe.zhong at rivai dot ai> ---
Hi, Robin.
Will you fix this bug ?
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vect-cost-model (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv)
2024-03-26 4:34 [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3 patrick at rivosinc dot com
` (7 preceding siblings ...)
2024-04-03 1:48 ` juzhe.zhong at rivai dot ai
@ 2024-04-03 12:05 ` rdapp at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: rdapp at gcc dot gnu.org @ 2024-04-03 12:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114476
--- Comment #8 from Robin Dapp <rdapp at gcc dot gnu.org> ---
I tried some things (for the related bug without -fwrapv) then got busy with
some other things. I'm going to have another look later this week.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-04-03 12:05 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-26 4:34 [Bug target/114476] New: [14] RISC-V rv64gcv vector: Runtime mismatch at -O3 patrick at rivosinc dot com
2024-03-26 5:04 ` [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vector-cost-mode (and -march=armv9-a+sve2 on aarch64 and -march=rv64gcv on riscv) pinskia at gcc dot gnu.org
2024-03-26 5:05 ` pinskia at gcc dot gnu.org
2024-03-26 5:10 ` pinskia at gcc dot gnu.org
2024-03-26 5:16 ` pinskia at gcc dot gnu.org
2024-03-26 8:07 ` rguenth at gcc dot gnu.org
2024-03-26 12:47 ` rdapp at gcc dot gnu.org
2024-03-27 21:03 ` [Bug tree-optimization/114476] [13/14 Regression] wrong code with -fwrapv -O3 -fno-vect-cost-model " pinskia at gcc dot gnu.org
2024-04-03 1:48 ` juzhe.zhong at rivai dot ai
2024-04-03 12:05 ` rdapp at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).