[PATCH] D67800: [InstCombine] Fold a shifty implementation of clamp (e.g., clamp255).

Huihui Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 19 23:40:18 PDT 2019


huihuiz added a comment.

E.g., vmin generation for ARM target

test.c

  static inline int clamp255(int v) {
    return (((255 - (v)) >> 31) | (v)) & 255;
  }
  
  
  void foo(const unsigned char* src1,
           const unsigned char* src2,
           unsigned char* dst,
                  int width) {
    int i;
    for (i = 0; i < width; ++i) {
      int r = src1[i];
      int b = src2[i];
      dst[0] = (unsigned char)clamp255(r + b);
      dst ++ ;
    }
  }

run: clang -cc1  -triple armv8.1a-linux-gnu -target-abi apcs-gnu -target-feature +neon -vectorize-loops -vectorize-slp -O2 -S -o - test.c -o -

you can see "vmin" generation

before this optimization, generate "vsub + vshr + vorr" instead.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67800/new/

https://reviews.llvm.org/D67800





More information about the llvm-commits mailing list