[PATCH] D25987: [X86] New pattern to generate PSUBUS from SELECT

Yulia Koval via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 26 07:29:23 PDT 2016

yulia_koval created this revision.
yulia_koval added reviewers: bkramer, nadav, RKSimon, spatel.
yulia_koval added subscribers: llvm-commits, DavidKreitzer, zansari, nikolai.bozhenov.

This patch recognizes pattern, when subtracted value of select's condition is wider, than source and destination values. In this case the wider value is replaced by max value of source value type.

void foo(unsigned short *p, int max, int n) {

  int i;
  unsigned m;
  for (i = 0; i < n; i++) {
      m = *--p;
      *p = (unsigned short)(m >= max ? m-max : 0);

In this example, select can't be combined to psubus, because max is 32 bit. But this patch makes it 16 bit, and it enables psubus selection. Max in this example is truncated to max_short value, if it is greater than m, or just truncated to 16 bit, if it is not. It is vaid transformation, because if max > max_short, result of the expression will be zero.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25987.75873.patch
Type: text/x-patch
Size: 5490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161026/50159839/attachment.bin>

More information about the llvm-commits mailing list