Re: Missed compiler optimization issue in function select_rtable_names_for_explain

2024-05-22 Thread Tom Lane
Alvaro Herrera writes: > I think if we want to improve how this code is seen by the compiler by > modifying it, we should just remove the NULL/NIL assignments. It's a > pretty arbitrary (and rather small) subset of fields being initialized, > fields which very obviously have been zeroed by memset

Re: Missed compiler optimization issue in function select_rtable_names_for_explain

2024-05-22 Thread Daniel Gustafsson
> On 22 May 2024, at 18:53, Tom Lane wrote: > > Daniel Gustafsson writes: >> They are known to be zero, but that's not entirely equivalent though is it? >> NIL is defined as ((List *) NULL) and NULL is typically defined as ((void *) >> 0), so sizeof(0) would be the size of an int and sizeof(NULL

Re: Missed compiler optimization issue in function select_rtable_names_for_explain

2024-05-22 Thread Daniel Gustafsson
> On 22 May 2024, at 13:00, Alvaro Herrera wrote: > I think if we want to improve how this code is seen by the compiler by > modifying it, we should just remove the NULL/NIL assignments. *If* the optimization is measurable, IMHO. > It's a > pretty arbitrary (and rather small) subset of fields b

Re: Missed compiler optimization issue in function select_rtable_names_for_explain

2024-05-22 Thread Alvaro Herrera
On 2024-May-22, XChy wrote: > Hi everyone, > > I'm a compiler developer working on detecting missed optimization in > real-world applications. Recently, we found that LLVM missed a dead store > elimination optimization in the PostgreSQL code >

Re: Missed compiler optimization issue in function select_rtable_names_for_explain

2024-05-22 Thread Tom Lane
Daniel Gustafsson writes: > They are known to be zero, but that's not entirely equivalent though is it? > NIL is defined as ((List *) NULL) and NULL is typically defined as ((void *) > 0), so sizeof(0) would be the size of an int and sizeof(NULL) would be the > size > of a void pointer. There ar

Re: Missed compiler optimization issue in function select_rtable_names_for_explain

2024-05-22 Thread XChy
在 2024/5/22 18:55, Daniel Gustafsson 写道: I mean that the stores with value "0" after the memset are dead: ``` dpns.subplans = NIL; dpns.ctes = NIL; dpns.appendrels = NULL; ``` since the memset has written zeroes to the object "dpns", and these members are known to be zero. They

Re: Missed compiler optimization issue in function select_rtable_names_for_explain

2024-05-22 Thread Daniel Gustafsson
> On 22 May 2024, at 12:12, XChy wrote: > >> How is the memset in select_rtable_names_for_explain a dead-store? Even >> memset calls could be optimized away from the EXPLAIN codepath I have a >> feeling it >> would have to be many in a tight loop for it to be measurable even? > For the first q

Re: Missed compiler optimization issue in function select_rtable_names_for_explain

2024-05-22 Thread XChy
How is the memset in select_rtable_names_for_explain a dead-store? Even memset calls could be optimized away from the EXPLAIN codepath I have a feeling it would have to be many in a tight loop for it to be measurable even? -- Daniel Gustafsson For the first question, I don't mean that the mems

Re: Missed compiler optimization issue in function select_rtable_names_for_explain

2024-05-22 Thread Daniel Gustafsson
> On 22 May 2024, at 11:27, XChy wrote: > > Hi everyone, > I'm a compiler developer working on detecting missed optimization in > real-world applications. Recently, we found that LLVM missed a dead store > elimination optimization in the PostgreSQL code > (https://github.com/postgres/postgres/

Missed compiler optimization issue in function select_rtable_names_for_explain

2024-05-22 Thread XChy
Hi everyone, I'm a compiler developer working on detecting missed optimization in real-world applications. Recently, we found that LLVM missed a dead store elimination optimization in the PostgreSQL code