[DAG] Match USUBSAT patterns through zext/trunc
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Sun, 21 Feb 2021 15:26:54 +0000 (15:26 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Sun, 21 Feb 2021 15:26:54 +0000 (15:26 +0000)
commit38ab47c8136d4f928cfd4babb89cb3c7ab783437
treedf07378abd2f3d9fc464c5f02aa7f8213a4d3821
parenta6a258f1da37a678867bd29f7125417944bdecb2
[DAG] Match USUBSAT patterns through zext/trunc

This patch handles usubsat patterns hidden through zext/trunc and uses the getTruncatedUSUBSAT helper to determine if the USUBSAT can be correctly performed in the truncated form:

zext(x) >= y ? x - trunc(y) : 0 --> usubsat(x,trunc(umin(y,SatLimit)))
zext(x) >  y ? x - trunc(y) : 0 --> usubsat(x,trunc(umin(y,SatLimit)))

Based on original examples:

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);
    }
}

Differential Revision: https://reviews.llvm.org/D25987
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/psubus.ll