Skip to content

Commit 7917b15

Browse files
nikictstellar
authored andcommitted
[CodeGen] Always expand division larger than i128
Default MaxDivRemBitWidthSupported to 128, so that divisions larger than 128 bits are always expanded, without requiring additional configuration from the target. Note that this may still emit calls to __udivti3 on 32-bit targets, which likely don't have an implementation of that builtin. However, I believe this is sufficient to fix #60531, because Zig must already be defining those builtins. Differential Revision: https://reviews.llvm.org/D144871 (cherry picked from commit ddccc5b)
1 parent 46cfe51 commit 7917b15

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,9 @@ TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm) : TM(tm) {
724724
// with the Target-specific changes necessary.
725725
MaxAtomicSizeInBitsSupported = 1024;
726726

727-
MaxDivRemBitWidthSupported = llvm::IntegerType::MAX_INT_BITS;
727+
// Assume that even with libcalls, no target supports wider than 128 bit
728+
// division.
729+
MaxDivRemBitWidthSupported = 128;
728730

729731
MaxLargeFPConvertBitWidthSupported = llvm::IntegerType::MAX_INT_BITS;
730732

llvm/test/CodeGen/Mips/idiv_large.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=mips-- < %s | FileCheck %s
3+
; RUN: llc -mtriple=mips64-- < %s | FileCheck %s
4+
5+
define i128 @udiv_i128(i128 %x, i128 %y) nounwind {
6+
; CHECK-LABEL: udiv_i128:
7+
; CHECK: jal __udivti3
8+
%res = udiv i128 %x, %y
9+
ret i128 %res
10+
}
11+
12+
define i129 @udiv_i129(i129 %x, i129 %y) nounwind {
13+
; CHECK-LABEL: udiv_i129:
14+
; CHECK-NOT: jal
15+
%res = udiv i129 %x, %y
16+
ret i129 %res
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=powerpc-- < %s | FileCheck %s
3+
; RUN: llc -mtriple=powerpc64-- < %s | FileCheck %s
4+
5+
define i128 @udiv_i128(i128 %x, i128 %y) nounwind {
6+
; CHECK-LABEL: udiv_i128:
7+
; CHECK: bl __udivti3
8+
%res = udiv i128 %x, %y
9+
ret i128 %res
10+
}
11+
12+
define i129 @udiv_i129(i129 %x, i129 %y) nounwind {
13+
; CHECK-LABEL: udiv_i129:
14+
; CHECK-NOT: bl __
15+
%res = udiv i129 %x, %y
16+
ret i129 %res
17+
}

llvm/test/CodeGen/RISCV/idiv_large.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=riscv32 < %s | FileCheck %s
3+
; RUN: llc -mtriple=riscv64 < %s | FileCheck %s
4+
5+
define i128 @udiv_i128(i128 %x, i128 %y) nounwind {
6+
; CHECK-LABEL: udiv_i128:
7+
; CHECK: call __udivti3
8+
%res = udiv i128 %x, %y
9+
ret i128 %res
10+
}
11+
12+
define i129 @udiv_i129(i129 %x, i129 %y) nounwind {
13+
; CHECK-LABEL: udiv_i129:
14+
; CHECK-NOT: call{{.*}}div
15+
%res = udiv i129 %x, %y
16+
ret i129 %res
17+
}

0 commit comments

Comments
 (0)