[PATCH] D90218: Fix PR47973: Addressing integer division edge case with INT_MIN
Ayshe Kuran via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 28 03:53:30 PDT 2020
akuran updated this revision to Diff 301222.
akuran added a comment.
Restart build
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90218/new/
https://reviews.llvm.org/D90218
Files:
compiler-rt/lib/builtins/int_div_impl.inc
Index: compiler-rt/lib/builtins/int_div_impl.inc
===================================================================
--- compiler-rt/lib/builtins/int_div_impl.inc
+++ compiler-rt/lib/builtins/int_div_impl.inc
@@ -72,24 +72,24 @@
#ifdef COMPUTE_UDIV
static __inline fixint_t __divXi3(fixint_t a, fixint_t b) {
const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1;
- fixint_t s_a = a >> N; // s_a = a < 0 ? -1 : 0
- fixint_t s_b = b >> N; // s_b = b < 0 ? -1 : 0
- a = (a ^ s_a) - s_a; // negate if s_a == -1
- b = (b ^ s_b) - s_b; // negate if s_b == -1
- s_a ^= s_b; // sign of quotient
- return (COMPUTE_UDIV(a, b) ^ s_a) - s_a; // negate if s_a == -1
+ fixint_t s_a = a >> N; // s_a = a < 0 ? -1 : 0
+ fixint_t s_b = b >> N; // s_b = b < 0 ? -1 : 0
+ fixuint_t a_u = (fixuint_t)(a ^ s_a) + (-s_a); // negate if s_a == -1
+ fixuint_t b_u = (fixuint_t)(b ^ s_b) + (-s_b); // negate if s_b == -1
+ s_a ^= s_b; // sign of quotient
+ return (COMPUTE_UDIV(a_u, b_u) ^ s_a) + (-s_a); // negate if s_a == -1
}
#endif // COMPUTE_UDIV
#ifdef ASSIGN_UMOD
static __inline fixint_t __modXi3(fixint_t a, fixint_t b) {
const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1;
- fixint_t s = b >> N; // s = b < 0 ? -1 : 0
- b = (b ^ s) - s; // negate if s == -1
- s = a >> N; // s = a < 0 ? -1 : 0
- a = (a ^ s) - s; // negate if s == -1
+ fixint_t s = b >> N; // s = b < 0 ? -1 : 0
+ fixuint_t b_u = (fixuint_t)(b ^ s) + (-s); // negate if s == -1
+ s = a >> N; // s = a < 0 ? -1 : 0
+ fixuint_t a_u = (fixuint_t)(a ^ s) + (-s); // negate if s == -1
fixuint_t res;
- ASSIGN_UMOD(res, a, b);
- return (res ^ s) - s; // negate if s == -1
+ ASSIGN_UMOD(res, a_u, b_u);
+ return (res ^ s) + (-s); // negate if s == -1
}
#endif // ASSIGN_UMOD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90218.301222.patch
Type: text/x-patch
Size: 2107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201028/b1b91035/attachment.bin>
More information about the llvm-commits
mailing list