[PATCH] D111804: [InstCombine] Don't combine CmpInst that used for verify the legality of the lshr

Tiehu Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 14 19:20:34 PDT 2021


TiehuZhang added a comment.

In D111804#3064140 <https://reviews.llvm.org/D111804#3064140>, @lebedev.ri wrote:

> Sorry, but i can not parse the description,
>
> The current transformation is *not* a miscompile:
> https://godbolt.org/z/WeTeasK53
> https://alive2.llvm.org/ce/z/LVDqSX

I'm sorry I didn't make my point clear. The purpose of my current modification is to circumvent a false optimization. In, the case, `%0` may be `0`. If we eliminate `%cmp = icmp slt i32 %0, 0`, undefined behavior may occur, as lshr performed a negative shift. @@lebedev.ri

original version

  %cmp = icmp slt i32 %0, 0
  %shr = lshr i32 7, %0
  %cmp1 = icmp sgt i32 %0, %shr
  %or.cond = or i1 %cmp, %cmp1
  br i1 %or.cond, label %cond.end, label %cond.false

miscompile

  %shr = lshr i32 7, %0
  %1 = icmp ult i32 %shr, %0
  br i1 %1, label %cond.end, label %cond.false


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111804



More information about the llvm-commits mailing list