Bug 97042 - powerpc64 UINT_MAX constant
Summary: powerpc64 UINT_MAX constant
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2020-09-14 04:10 UTC by Alan Modra
Modified: 2022-03-08 16:20 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc64
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-09-15 00:00:00


Attachments
proposed patch for the ICEs (wrong PR, sorry) (350 bytes, patch)
2020-09-14 14:31 UTC, Segher Boessenkool
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Modra 2020-09-14 04:10:49 UTC
/* -O2 -S */
long foo (long x) { return ~0u - x; }

for gcc-8 to current master
	lis 9,0xffff
	ori 9,9,0xffff
	rldicl 9,9,0,32
	subf 3,3,9
	blr

a regression from gcc-7
	li 9,-1
	rldicl 9,9,0,32
	subf 3,3,9
	blr

Both sequences give the same result, this is just a code quality regression.

I haven't properly debugged this but I suspect commit 5d3ae76af13
Comment 1 Alan Modra 2020-09-14 04:40:28 UTC
Yes, reverting 5d3ae76af13 cures this PR.
Comment 2 Peter Bergner 2020-09-14 12:38:49 UTC
With a patch I'm working on for PR93176, I get the following code (even with the commit below):

	li 9,-1
	rldic 9,9,0,32
	subf 3,3,9
	blr
Comment 3 Segher Boessenkool 2020-09-14 14:31:32 UTC
Created attachment 49214 [details]
proposed patch for the ICEs  (wrong PR, sorry)
Comment 4 Segher Boessenkool 2020-09-14 14:33:31 UTC Comment hidden (obsolete)
Comment 5 Segher Boessenkool 2020-09-14 14:38:28 UTC
So hrm, why did GCC generate  lis 0xffff ; ori 0xffff ; rldicl  instead of
li 0xffff ; oris 0xffff  ?
Comment 6 Alan Modra 2020-09-14 22:49:58 UTC
That's easy.  rs6000_emit_set_long_const doesn't generate that sequence.

Incidentally, a patch I had to generate more constants from li;rldicl also fixes this pr.
Comment 7 Alan Modra 2020-09-14 23:34:41 UTC
and of course, li 0xffff is li -1 which sets all bits.
Comment 8 Segher Boessenkool 2020-09-15 00:28:04 UTC
(In reply to Alan Modra from comment #7)
> and of course, li 0xffff is li -1 which sets all bits.

Erm, yes.  Duh.

So that g:5d3ae76af13 splitter should not fire for numbers that fit in
32 bits but that have the high bit of both 16-bit halfs set.
Comment 9 Alan Modra 2020-09-15 01:33:49 UTC
I think that splitter should disappear and rs6000_emit_set_long_const handle all special cases where you might want combinations of two logical instructions before handling the li;rldicl, li;rldicr or any other expansions with rotates.
Comment 10 Segher Boessenkool 2020-09-15 13:32:09 UTC
(In reply to Alan Modra from comment #9)
> I think that splitter should disappear and rs6000_emit_set_long_const handle
> all special cases where you might want combinations of two logical
> instructions before handling the li;rldicl, li;rldicr or any other
> expansions with rotates.

Yeah, that would be much easier to read and maintain.  Good plan.