Bug 45861 - Possible missed optimization - array ops vs shift-and-mask
Summary: Possible missed optimization - array ops vs shift-and-mask
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.5.1
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: missed-optimization
Depends on:
Reported: 2010-10-01 18:31 UTC by Zack Weinberg
Modified: 2012-02-04 02:54 UTC (History)
0 users

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2012-02-03 00:00:00

test case (228 bytes, text/x-csrc)
2010-10-01 18:31 UTC, Zack Weinberg
assembly for test case with gcc 4.5.1 on x86-64 (359 bytes, text/plain)
2010-10-01 18:32 UTC, Zack Weinberg

Note You need to log in before you can comment on or make changes to this bug.
Description Zack Weinberg 2010-10-01 18:31:54 UTC
Created attachment 21938 [details]
test case

The attached .c file contains two functions, which (unless I screwed up) compute exactly the same (mathematical) function - they take an array of 8 bytes, permute its elements, and stuff them into a 64-bit integer, which is then returned.  However, GCC generates very different code for each (on x86-64).  There seem to be two missed optimization opportunities here:

1) I don't know *which* of the two code generation possibilities here is better, but it seems like GCC ought to know and ought to generate that code for both functions.

2) Could we be taking advantage of SSEn vector permute instructions here?
Comment 1 Zack Weinberg 2010-10-01 18:32:32 UTC
Created attachment 21939 [details]
assembly for test case with gcc 4.5.1 on x86-64
Comment 2 Richard Biener 2010-10-03 19:46:13 UTC
We do at least have some infrastructure for this kind of optimization
(the bswap pass).  But it needs to be taught of memory source/destinations
and SSE shuffles.