Re: [PATCH 4/4] pipe_fs_i.h: add pipe_buf_init()

From: Al Viro
Date: Sat Mar 12 2022 - 23:34:42 EST


On Sun, Mar 13, 2022 at 02:48:10AM +0000, Matthew Wilcox wrote:

> That's not equivalent. I think the better option here is to always
> initialise flags to 0 (and not have a parameter for it):
>
> pipe_buf_init(buf, page, 0, 0, &anon_pipe_buf_ops);
> if (is_packetized(filp))
> buf->flags = PIPE_BUF_FLAG_PACKET;
> else
> buf->flags = PIPE_BUF_FLAG_CAN_MERGE;

Not equivalent in which sense? IDGI... Your variant is basically

X = 0;
if (Y == constant)
X = 1;
else
X = 2;

If gcc can optimize that to

X = (Y == constant) ? 1 : 2;

it should be able to do the same to
X = 1;
if (Y != constant)
X = 2;

What obstacles are there, besides a (false) assumption that
X might alias Y? Which would apply to both variants... Granted, I'm
half-asleep right now, so I might be missing something obvious...