[PATCH] D65151: [InstSimplify] Drop leftover "division-by-zero guard" around `@llvm.umul.with.overflow` inverted overflow bit

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 08:46:14 PDT 2019


lebedev.ri added a comment.

One more thing: given this IR:

  define dso_local i64 @_Z17will_not_overflowmmPb(i64 %arg, i64 %arg1, i8* nocapture %arg2) {
    %tmp = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %arg, i64 %arg1)
    %tmp3 = extractvalue { i64, i1 } %tmp, 1
    %tmp4 = zext i1 %tmp3 to i8
    store i8 %tmp4, i8* %arg2, align 1
    %tmp5 = mul i64 %arg1, %arg
    ret i64 %tmp5
  }
  
  declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64)

which pass should be responsible to merging those two multiplications into:

  define dso_local i64 @_Z17will_not_overflowmmPb(i64 %arg, i64 %arg1, i8* nocapture %arg2) {
    %tmp = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %arg, i64 %arg1)
    %tmp3 = extractvalue { i64, i1 } %tmp, 1
    %tmp4 = zext i1 %tmp3 to i8
    store i8 %tmp4, i8* %arg2, align 1
    %tmp5 = extractvalue { i64, i1 } %tmp, 0
    ret i64 %tmp5
  }
  
  declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64)

?

https://godbolt.org/z/CQW8it

  ----------------------------------------
  Name: mul -> smul_overflow
    %r = mul i4 %x, %y
  =>
    %tmp = smul_overflow i4 %x, %y
    %r = extractvalue {i4, i1} %tmp, 0
  
  Done: 1
  Optimization is correct!
  
  ----------------------------------------
  Name: mul -> umul_overflow
    %r = mul i4 %x, %y
  =>
    %tmp = umul_overflow i4 %x, %y
    %r = extractvalue {i4, i1} %tmp, 0
  
  Done: 1
  Optimization is correct!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65151





More information about the llvm-commits mailing list