[PATCH] D41149: [CodeGen] Specialize mixed-sign mul-with-overflow (fix PR34920)

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 12 17:55:02 PST 2017


vsk created this revision.
vsk added reviewers: efriedma, rjmccall, dtzWill.

This patch introduces a specialized way to lower overflow-checked
multiplications with mixed-sign operands. This fixes link failures and
ICEs on code like this:

  void mul(int64_t a, uint64_t b) {
    int64_t res;
    __builtin_mul_overflow(a, b, &res);
  }

The generic checked-binop irgen would use a 65-bit multiplication
intrinsic here, which requires runtime support for _muloti4 (128-bit
multiplication), and therefore fails to link on i386. To get an ICE
on x86_64, change the example to use __int128_t / __uint128_t.

Adding runtime and backend support for 65-bit or 129-bit checked
multiplication on all of our supported targets is infeasible.

This patch solves the problem by using simpler, specialized irgen for
the mixed-sign case.

llvm.org/PR34920, rdar://34963321

Testing: check-clang, and making sure the output of oflow.cc is the same
with and without the patch on x86_64.

F5676414: oflow.cc <https://reviews.llvm.org/F5676414>


https://reviews.llvm.org/D41149

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtins-overflow.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41149.126665.patch
Type: text/x-patch
Size: 6672 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171213/0dff9bfb/attachment.bin>


More information about the cfe-commits mailing list