Skip to content

Commit ed9fb1b

Browse files
nickdesaulniersmemfrob
authored andcommitted
[MipsISelLowering] avoid emitting libcalls to __multi3
Similar to D108842 and D108844. __has_builtin(builtin_mul_overflow) returns true for 32b MIPS targets, but Clang is deferring to compiler RT when encountering long long types. This breaks MIPS malta_defconfig builds of the Linux kernel that are using __builtin_mul_overflow with these types for these targets. If the semantics of __has_builtin mean "the compiler resolves these, always" then we shouldn't conditionally emit a libcall. This will still need to be worked around in the Linux kernel in order to continue to support malta_defconfig builds of the Linux kernel for this target with older releases of clang. Link: https://bugs.llvm.org/show_bug.cgi?id=28629 Link: ClangBuiltLinux/linux#1438 Reviewed By: rengolin Differential Revision: https://reviews.llvm.org/D108926
1 parent 3bb2850 commit ed9fb1b

File tree

4 files changed

+43
-33
lines changed

4 files changed

+43
-33
lines changed

llvm/lib/Target/Mips/MipsISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
509509
setLibcallName(RTLIB::SHL_I128, nullptr);
510510
setLibcallName(RTLIB::SRL_I128, nullptr);
511511
setLibcallName(RTLIB::SRA_I128, nullptr);
512+
setLibcallName(RTLIB::MUL_I128, nullptr);
512513
setLibcallName(RTLIB::MULO_I64, nullptr);
513514
setLibcallName(RTLIB::MULO_I128, nullptr);
514515
}

llvm/test/CodeGen/Mips/llvm-ir/mul.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ define signext i128 @mul_i128(i128 signext %a, i128 signext %b) {
230230
entry:
231231
; ALL-LABEL: mul_i128:
232232

233-
; GP32: lw $25, %call16(__multi3)($gp)
233+
; GP32-NOT: lw $25, %call16(__multi3)($gp)
234234

235235
; GP64-NOT-R6: dmult $4, $7
236236
; GP64-NOT-R6: mflo $[[T0:[0-9]+]]
@@ -249,7 +249,7 @@ entry:
249249
; 64R6: daddu $2, $[[T1]], $[[T0]]
250250
; 64R6-DAG: dmul $3, $5, $7
251251

252-
; MM32: lw $25, %call16(__multi3)($16)
252+
; MM32-NOT: lw $25, %call16(__multi3)($16)
253253

254254
%r = mul i128 %a, %b
255255
ret i128 %r

llvm/test/CodeGen/Mips/overflow-intrinsic-optimizations.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
define i1 @no__mulodi4(i32 %a, i64 %b, i32* %c) {
44
; CHECK-LABEL: no__mulodi4
55
; CHECK-NOT: jal __mulodi4
6+
; CHECK-NOT: jal __multi3
67
entry:
78
%0 = sext i32 %a to i64
89
%1 = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %0, i64 %b)

llvm/test/CodeGen/Mips/urem-seteq-illegal-types.ll

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -148,43 +148,51 @@ define i1 @test_urem_negative_odd(i9 %X) nounwind {
148148
define i1 @test_urem_oversized(i66 %X) nounwind {
149149
; MIPSEL-LABEL: test_urem_oversized:
150150
; MIPSEL: # %bb.0:
151-
; MIPSEL-NEXT: addiu $sp, $sp, -40
152-
; MIPSEL-NEXT: sw $ra, 36($sp) # 4-byte Folded Spill
153-
; MIPSEL-NEXT: move $7, $6
154-
; MIPSEL-NEXT: move $6, $5
155-
; MIPSEL-NEXT: move $5, $4
156151
; MIPSEL-NEXT: lui $1, 12057
157152
; MIPSEL-NEXT: ori $1, $1, 37186
158-
; MIPSEL-NEXT: lui $2, 52741
159-
; MIPSEL-NEXT: ori $2, $2, 40665
160-
; MIPSEL-NEXT: sw $2, 28($sp)
161-
; MIPSEL-NEXT: sw $1, 24($sp)
162-
; MIPSEL-NEXT: addiu $1, $zero, 2
163-
; MIPSEL-NEXT: sw $1, 20($sp)
164-
; MIPSEL-NEXT: sw $zero, 16($sp)
165-
; MIPSEL-NEXT: jal __multi3
166-
; MIPSEL-NEXT: addiu $4, $zero, 0
167-
; MIPSEL-NEXT: sll $1, $4, 31
168-
; MIPSEL-NEXT: srl $2, $5, 1
169-
; MIPSEL-NEXT: or $1, $2, $1
170-
; MIPSEL-NEXT: lui $2, 60010
171-
; MIPSEL-NEXT: ori $2, $2, 61135
172-
; MIPSEL-NEXT: sltu $1, $1, $2
173-
; MIPSEL-NEXT: srl $2, $4, 1
174-
; MIPSEL-NEXT: andi $3, $3, 3
175-
; MIPSEL-NEXT: sll $4, $3, 31
176-
; MIPSEL-NEXT: or $4, $2, $4
153+
; MIPSEL-NEXT: multu $6, $1
154+
; MIPSEL-NEXT: mflo $2
155+
; MIPSEL-NEXT: mfhi $3
156+
; MIPSEL-NEXT: lui $7, 52741
157+
; MIPSEL-NEXT: ori $7, $7, 40665
158+
; MIPSEL-NEXT: multu $6, $7
159+
; MIPSEL-NEXT: mflo $8
160+
; MIPSEL-NEXT: mfhi $9
161+
; MIPSEL-NEXT: multu $5, $7
162+
; MIPSEL-NEXT: mfhi $10
163+
; MIPSEL-NEXT: mflo $11
164+
; MIPSEL-NEXT: addu $9, $11, $9
165+
; MIPSEL-NEXT: addu $12, $2, $9
166+
; MIPSEL-NEXT: sltu $9, $9, $11
167+
; MIPSEL-NEXT: sll $11, $12, 31
168+
; MIPSEL-NEXT: sltu $2, $12, $2
169+
; MIPSEL-NEXT: srl $13, $8, 1
170+
; MIPSEL-NEXT: sll $8, $8, 1
171+
; MIPSEL-NEXT: addu $2, $3, $2
172+
; MIPSEL-NEXT: or $3, $13, $11
173+
; MIPSEL-NEXT: srl $11, $12, 1
174+
; MIPSEL-NEXT: addu $9, $10, $9
175+
; MIPSEL-NEXT: mul $4, $4, $7
176+
; MIPSEL-NEXT: mul $1, $5, $1
177+
; MIPSEL-NEXT: sll $5, $6, 1
178+
; MIPSEL-NEXT: lui $6, 60010
179+
; MIPSEL-NEXT: ori $6, $6, 61135
180+
; MIPSEL-NEXT: addu $2, $9, $2
181+
; MIPSEL-NEXT: addu $1, $1, $2
182+
; MIPSEL-NEXT: addu $2, $5, $4
183+
; MIPSEL-NEXT: addu $1, $1, $2
184+
; MIPSEL-NEXT: andi $1, $1, 3
185+
; MIPSEL-NEXT: sll $2, $1, 31
186+
; MIPSEL-NEXT: or $4, $11, $2
177187
; MIPSEL-NEXT: sltiu $2, $4, 13
178188
; MIPSEL-NEXT: xori $4, $4, 13
179-
; MIPSEL-NEXT: movz $2, $1, $4
180-
; MIPSEL-NEXT: sll $1, $5, 1
181-
; MIPSEL-NEXT: srl $3, $3, 1
182-
; MIPSEL-NEXT: or $1, $3, $1
189+
; MIPSEL-NEXT: sltu $3, $3, $6
190+
; MIPSEL-NEXT: movz $2, $3, $4
191+
; MIPSEL-NEXT: srl $1, $1, 1
192+
; MIPSEL-NEXT: or $1, $1, $8
183193
; MIPSEL-NEXT: andi $1, $1, 3
184-
; MIPSEL-NEXT: movn $2, $zero, $1
185-
; MIPSEL-NEXT: lw $ra, 36($sp) # 4-byte Folded Reload
186194
; MIPSEL-NEXT: jr $ra
187-
; MIPSEL-NEXT: addiu $sp, $sp, 40
195+
; MIPSEL-NEXT: movn $2, $zero, $1
188196
;
189197
; MIPS64EL-LABEL: test_urem_oversized:
190198
; MIPS64EL: # %bb.0:

0 commit comments

Comments
 (0)