[PATCH] D63065: [InstSimplify] Fix addo/subo undef folds (PR42209)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 15 16:22:40 PDT 2019


lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

In D63065#1544780 <https://reviews.llvm.org/D63065#1544780>, @nikic wrote:

> @lebedev.ri It's not possible to fold to `{ i8 undef, i1 false }`. As a counter-example `uaddo(1, undef)` can never have the value `{ 0, false }`. Reaching the zero value would have required overflow, which is precluded by the overflow result. Similar cases exist for the other intrinsics as well.


Ok so. I *think* i'm finally holding `alive` the right way, gently-enough, and breathing in other direction to not disturb it.
And it does not agree with that statement:

  $ .../alive  -root-only /tmp/test.opt  
  OMP: Info #270: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.
  Processing /tmp/test.opt..
  
  ----------------------------------------
  Name: zz
    %undef0 = udiv i8 %a, 0
    %X = uadd_overflow i8 1, %undef0
    %Y = extractvalue {i8, i1} %X, 0
    %Z = extractvalue {i8, i1} %X, 1
    ret %Y
  =>
    %undef0 = udiv i8 %a, 0
    %X = uadd_overflow i8 1, %undef0
    %Y = 0
    %Z = 0
    ret %Y
  
  Done: 64
  Optimization is correct!
  
  ----------------------------------------
  Name: zz 2
    %undef0 = udiv i8 %a, 0
    %X = uadd_overflow i8 1, %undef0
    %Y = extractvalue {i8, i1} %X, 0
    %Z = extractvalue {i8, i1} %X, 1
    ret %Z
  =>
    %undef0 = udiv i8 %a, 0
    %X = uadd_overflow i8 1, %undef0
    %Y = 0
    %Z = 0
    ret %Z
  
  Done: 64
  Optimization is correct!

In fact, it tells me that my suggestion about folding all 4 of `@llvm.{u,s}{add,sub}.with.overflow` to `{undef, false}` is correct.
And the `@llvm.{u,s}mul.with.overflow` can all be folded to `{0, false}`


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63065





More information about the llvm-commits mailing list