the elimination of if blocks in GCC during if-conversion and vectorization

2023-10-12 Thread Hanke Zhang via Gcc
Hi, I'm recently working on vectorization of GCC. I'm stuck in a small
problem and would like to ask for advice.

For example, for the following code:

int main() {
  int size = 1000;
  int *foo = malloc(sizeof(int) * size);
  int c1 = rand(), t1 = rand();

  for (int i = 0; i < size; i++) {
if (foo[i] & c1) {
  foo[i] = t1;
}
  }

  // prevents the loop above from being optimized
  for (int i = 0; i < size; i++) {
printf("%d", foo[i]);
  }
}

First of all, the if statement block in the loop will be converted to
a MASK_STORE through if-conversion optimization. But after
tree-vector, it will still become a branched form. The part of the
final disassembly structure probably looks like below(Using IDA to do
this), and you can see that there is still such a branch 'if ( !_ZF )'
in it, which will lead to low efficiency.

do
  {
while ( 1 )
{
  __asm
  {
vpand   ymm0, ymm2, ymmword ptr [rax]
vpcmpeqd ymm0, ymm0, ymm1
vpcmpeqd ymm0, ymm0, ymm1
vptest  ymm0, ymm0
  }
  if ( !_ZF )
break;
  _RAX += 8;
  if ( _RAX == v9 )
goto LABEL_5;
}
__asm { vpmaskmovd ymmword ptr [rax], ymm0, ymm3 }
_RAX += 8;
  }
  while ( _RAX != v9 );

Why can't we just replace the vptest and if statement with some other
instructions like vpblendvb so that it can be faster? Or is there a
good way to do that?

Thanks
Hanke Zhang


gcc-11-20231012 is now available

2023-10-12 Thread GCC Administrator via Gcc
Snapshot gcc-11-20231012 is now available on
  https://gcc.gnu.org/pub/gcc/snapshots/11-20231012/
and on various mirrors, see http://gcc.gnu.org/mirrors.html for details.

This snapshot has been generated from the GCC 11 git branch
with the following options: git://gcc.gnu.org/git/gcc.git branch 
releases/gcc-11 revision 157819cf80ffb3c6d0d6bd401b6a670c67b00830

You'll find:

 gcc-11-20231012.tar.xz   Complete GCC

  SHA256=0978c7ed27af2700a57c556cabf8ee8060855d8971c192f07e34b63f8d4b77db
  SHA1=76017b8839a527fc86ae822716cff3b53d7e9aee

Diffs from 11-20231005 are available in the diffs/ subdirectory.

When a particular snapshot is ready for public consumption the LATEST-11
link is updated and a message is sent to the gcc list.  Please do not use
a snapshot before it has been announced that way.