OSDN Git Service

[InstCombine] Take in account the size in sext->lshr->trunc patterns.
authorDavide Italiano <davide@freebsd.org>
Sun, 21 May 2017 20:30:27 +0000 (20:30 +0000)
committerDavide Italiano <davide@freebsd.org>
Sun, 21 May 2017 20:30:27 +0000 (20:30 +0000)
commit4276950084b80cbae3d716fb691cfe9700056786
treea89e877e0f7c4907946619bb86c46ca86feb0dd0
parent68ac6769cc9190b8286c2a798ab0ffa5ae034173
[InstCombine] Take in account the size in sext->lshr->trunc patterns.

Otherwise we end up miscompiling, transforming:

define i8 @tinky() {
  %sext = sext i1 1 to i16
  %hibit = lshr i16 %sext, 15
  %tr = trunc i16 %hibit to i8
  ret i8 %tr
}

into:

  %sext = sext i1 1 to i8
  ret i8 %sext

and the first get folded to ret i8 1, while the second gets folded
to ret i8 -1.

Eventually we should get rid of this transform entirely, but for now,
this at least fixes a know correctness bug.

Differential Revision:  https://reviews.llvm.org/D33338

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