public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103670] New: Incorrect optimization of loop termination: Early exit with any optimization
@ 2021-12-12 18:14 robert.muench at saphirion dot com
2021-12-12 19:54 ` [Bug c/103670] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: robert.muench at saphirion dot com @ 2021-12-12 18:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103670
Bug ID: 103670
Summary: Incorrect optimization of loop termination: Early exit
with any optimization
Product: gcc
Version: 10.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: robert.muench at saphirion dot com
Target Milestone: ---
Created attachment 51981
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51981&action=edit
Assembly output with & without -Os optimization
Whenever any -Ox option is used, the loop exits after 3 rounds, even the
counter should run for 6 rounds. Without any -O option, the code works as
expected.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/103670] Incorrect optimization of loop termination: Early exit with any optimization
2021-12-12 18:14 [Bug c/103670] New: Incorrect optimization of loop termination: Early exit with any optimization robert.muench at saphirion dot com
@ 2021-12-12 19:54 ` pinskia at gcc dot gnu.org
2021-12-12 21:04 ` [Bug middle-end/103670] " pinskia at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-12 19:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103670
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Can you provide the preprocessed source that is used to generate the assembly
file?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/103670] Incorrect optimization of loop termination: Early exit with any optimization
2021-12-12 18:14 [Bug c/103670] New: Incorrect optimization of loop termination: Early exit with any optimization robert.muench at saphirion dot com
2021-12-12 19:54 ` [Bug c/103670] " pinskia at gcc dot gnu.org
@ 2021-12-12 21:04 ` pinskia at gcc dot gnu.org
2021-12-12 23:14 ` robert.muench at saphirion dot com
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-12 21:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103670
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-12-12
Status|UNCONFIRMED |WAITING
Keywords| |wrong-code
Ever confirmed|0 |1
Component|c |middle-end
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/103670] Incorrect optimization of loop termination: Early exit with any optimization
2021-12-12 18:14 [Bug c/103670] New: Incorrect optimization of loop termination: Early exit with any optimization robert.muench at saphirion dot com
2021-12-12 19:54 ` [Bug c/103670] " pinskia at gcc dot gnu.org
2021-12-12 21:04 ` [Bug middle-end/103670] " pinskia at gcc dot gnu.org
@ 2021-12-12 23:14 ` robert.muench at saphirion dot com
2021-12-12 23:16 ` robert.muench at saphirion dot com
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: robert.muench at saphirion dot com @ 2021-12-12 23:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103670
--- Comment #2 from Robert M. Münch <robert.muench at saphirion dot com> ---
That's the code snippet. The for(...) loop is where things start to become
strange.
The thing is, if we use the code from a pure C program, it works. We are using
this code from a Windows DLL which we call via an FFI from an interpreter.
However, omitting any optimization makes it work.
if (pAdapter != NULL) {
int i = 0;
int offset = 0;
// loop for as many bytes as given by the address length
// sprintf returns num char written, take: out buffer, max size of buffer,
format, ...
// format: %[flags][width][.precision][size]type
// .2 = two characters
// type X = Unsigned hexadecimal integer; uses "ABCDEF"
// %.2X
LOG(" AddressLenth: %i", pAdapter->AddressLength); // MAC-48 = 48 bit, 6
bytes, 6 two char blocks
LOG(" mac: %.12X", pAdapter->Address);
for (i = 0; i < pAdapter->AddressLength; i++) {
LOG(" i: %i offset: %i, AddressLenth: %i", i, offset,
pAdapter->AddressLength);
// omit outputting the - char for the last byte
if (i == (pAdapter->AddressLength - 1)) {
LOG("%s", " finalizing MAC address buidling");
offset += sprintf_s(MacAddress + offset, MAX_ADAPTER_ADDRESS_LENGTH,
"%02X",pAdapter->Address[i]);
} else {
offset += sprintf_s(MacAddress + offset, MAX_ADAPTER_ADDRESS_LENGTH,
"%02X-",pAdapter->Address[i]);
}
}
LOG("<- OK: %s AddressLength: %i", MacAddress, i);
return MacAddress;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/103670] Incorrect optimization of loop termination: Early exit with any optimization
2021-12-12 18:14 [Bug c/103670] New: Incorrect optimization of loop termination: Early exit with any optimization robert.muench at saphirion dot com
` (2 preceding siblings ...)
2021-12-12 23:14 ` robert.muench at saphirion dot com
@ 2021-12-12 23:16 ` robert.muench at saphirion dot com
2021-12-12 23:22 ` pinskia at gcc dot gnu.org
2021-12-13 11:34 ` robert.muench at saphirion dot com
5 siblings, 0 replies; 7+ messages in thread
From: robert.muench at saphirion dot com @ 2021-12-12 23:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103670
--- Comment #3 from Robert M. Münch <robert.muench at saphirion dot com> ---
I updated to GCC 11.2, which has the same problem but after 4 rounds, not 3.
GCC 10.3 Output:
9512] ==> GetAdapterMACAddress
[9512] parameter check dwRetVal: 0 number: 0
[9512] AddressLenth: 6
[9512] i: 0 offset: 0, AddressLenth: 6
[9512] i: 1 offset: 3, AddressLenth: 6
[9512] i: 2 offset: 6, AddressLenth: 6
[9512] <- OK: 00-1C-42- AddressLength: 3
GCC 11.2 Output:
[7128] ==> GetAdapterMACAddress
[7128] parameter check dwRetVal: 0 number: 0
[7128] AddressLenth: 6
[7128] i: 0 offset: 0, AddressLenth: 6
[7128] i: 1 offset: 3, AddressLenth: 6
[7128] i: 2 offset: 6, AddressLenth: 6
[7128] i: 3 offset: 9, AddressLenth: 6
[7128] <- OK: 00-1C-42-10- AddressLength: 4
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/103670] Incorrect optimization of loop termination: Early exit with any optimization
2021-12-12 18:14 [Bug c/103670] New: Incorrect optimization of loop termination: Early exit with any optimization robert.muench at saphirion dot com
` (3 preceding siblings ...)
2021-12-12 23:16 ` robert.muench at saphirion dot com
@ 2021-12-12 23:22 ` pinskia at gcc dot gnu.org
2021-12-13 11:34 ` robert.muench at saphirion dot com
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-12 23:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103670
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Please read https://gcc.gnu.org/bugs/. A code snippet is not what we want. We
need a full compilable (not always runable) testcase for wrong code.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/103670] Incorrect optimization of loop termination: Early exit with any optimization
2021-12-12 18:14 [Bug c/103670] New: Incorrect optimization of loop termination: Early exit with any optimization robert.muench at saphirion dot com
` (4 preceding siblings ...)
2021-12-12 23:22 ` pinskia at gcc dot gnu.org
@ 2021-12-13 11:34 ` robert.muench at saphirion dot com
5 siblings, 0 replies; 7+ messages in thread
From: robert.muench at saphirion dot com @ 2021-12-13 11:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103670
Robert M. Münch <robert.muench at saphirion dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|WAITING |RESOLVED
--- Comment #5 from Robert M. Münch <robert.muench at saphirion dot com> ---
This was a wrong positive, caused by some weird side effect originating in some
far away place.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-12-13 11:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-12 18:14 [Bug c/103670] New: Incorrect optimization of loop termination: Early exit with any optimization robert.muench at saphirion dot com
2021-12-12 19:54 ` [Bug c/103670] " pinskia at gcc dot gnu.org
2021-12-12 21:04 ` [Bug middle-end/103670] " pinskia at gcc dot gnu.org
2021-12-12 23:14 ` robert.muench at saphirion dot com
2021-12-12 23:16 ` robert.muench at saphirion dot com
2021-12-12 23:22 ` pinskia at gcc dot gnu.org
2021-12-13 11:34 ` robert.muench at saphirion dot com
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).