[PATCH] D60669: [APInt] Optimize umul_ov

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 14 20:17:10 PDT 2019


MaskRay marked an inline comment as done.
MaskRay added a comment.

I have also fuzzed it for some time with libFuzzer to give me more confidence that it is correct.

  #include <llvm/ADT/APInt.h>
  
  extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
    using namespace llvm;
    unsigned n;
    uint64_t a, b;
    memcpy(&n, Data, 1);
    n = n%64+1;
    memcpy(&a, Data+1, 8);
    memcpy(&b, Data+9, 8);
  
    bool overflow, overflow1;
    APInt A(n, a), B(n, b), C = A.umul_ov(B, overflow), D = A * B;
    if (C != D) __builtin_trap();
  
    if (A != 0 && B != 0) overflow1 = D.udiv(A) != B;
    else overflow1 = false;
    if (overflow != overflow1) __builtin_trap();
  
    return 0;
  }


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60669





More information about the llvm-commits mailing list