OSDN Git Service

[InstCombine] narrow truncated add/sub/mul with constant
authorSanjay Patel <spatel@rotateright.com>
Fri, 4 Aug 2017 22:30:34 +0000 (22:30 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 4 Aug 2017 22:30:34 +0000 (22:30 +0000)
commit09cd716275747bd2559688f87195328b7223eef0
tree4d65cf4097962810c134f3cd295684683e13ca06
parent033f8efd27b44937696000ecfbaea01f563d5437
[InstCombine] narrow truncated add/sub/mul with constant

Name: narrow_sub
  %sub = sub i32 C1, %x
  %r = trunc i32 %sub to i8
  =>
  %xn = trunc i32 %x to i8
  %narrowC = trunc i32 C1 to i8
  %r = sub i8 %narrowC, %xn

Name: narrow_add
  %add = add i32 %x, C1
  %r = trunc i32 %add to i8
  =>
  %xn = trunc i32 %x to i8
  %narrowC = trunc i32 C1 to i8
  %r = add i8 %xn, %narrowC

Name: narrow_mul
  %mul = mul i32 %x, C1
  %r = trunc i32 %mul to i8
  =>
  %xn = trunc i32 %x to i8
  %narrowC = trunc i32 C1 to i8
  %r = mul i8 %xn, %narrowC

http://rise4fun.com/Alive/QpS

This doesn't solve PR34046 (failure to recognize rotate):
https://bugs.llvm.org/show_bug.cgi?id=34046
...but it reduces an extra complication in the description examples
to a form that we can more easily match.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310141 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCasts.cpp
test/Transforms/InstCombine/cast.ll
test/Transforms/InstCombine/ffs-1.ll
test/Transforms/InstCombine/fls.ll
test/Transforms/InstCombine/trunc.ll
test/Transforms/InstCombine/vec_phi_extract.ll