Skip to content

Commit 53e7da9

Browse files
authored
[SOL] Expand mulh for 32-bit (#127)
1 parent bbc016f commit 53e7da9

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

llvm/lib/Target/SBF/SBFISelLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ SBFTargetLowering::SBFTargetLowering(const TargetMachine &TM,
112112
setOperationAction(ISD::SELECT_CC, VT, Custom);
113113
}
114114

115+
if (STI.getHasPqrClass() && STI.getHasAlu32()) {
116+
setOperationAction(ISD::MULHU, MVT::i32, Expand);
117+
setOperationAction(ISD::MULHS, MVT::i32, Expand);
118+
}
119+
115120
if (STI.getHasAlu32()) {
116121
setOperationAction(ISD::BSWAP, MVT::i32, Promote);
117122
setOperationAction(ISD::BR_CC, MVT::i32, Custom);

llvm/test/CodeGen/SBF/mulh.ll

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
; RUN: llc -O2 -march=sbf -mcpu=v2 < %s | FileCheck %s
2+
3+
define dso_local i32 @test_32_unsigned(i32 noundef %a, i32 noundef %b) {
4+
entry:
5+
; CHECK-LABEL: test_32_unsigned
6+
%conv = zext i32 %a to i64
7+
%conv1 = zext i32 %b to i64
8+
%mul = mul nuw i64 %conv1, %conv
9+
%shr = lshr i64 %mul, 32
10+
%conv2 = trunc i64 %shr to i32
11+
ret i32 %conv2
12+
13+
; CHECK: mov64 w0, w2
14+
; CHECK: lmul64 r0, r1
15+
; CHECK: rsh64 r0, 32
16+
; CHECK: and32 w0, -1
17+
}
18+
19+
define dso_local i32 @test_32_signed(i32 noundef %a, i32 noundef %b) {
20+
entry:
21+
22+
; CHECK-LABEL: test_32_signed
23+
%conv = sext i32 %a to i64
24+
%conv1 = sext i32 %b to i64
25+
%mul = mul nsw i64 %conv1, %conv
26+
%shr = lshr i64 %mul, 32
27+
%conv2 = trunc i64 %shr to i32
28+
ret i32 %conv2
29+
30+
; CHECK: mov32 r1, w1
31+
; CHECK: mov32 r0, w2
32+
; CHECK: lmul64 r0, r1
33+
; CHECK: rsh64 r0, 32
34+
; CHECK: and32 w0, -1
35+
36+
}
37+
38+
define dso_local i64 @test_64_unsigned(i64 noundef %a, i64 noundef %b) {
39+
entry:
40+
; CHECK-LABEL: test_64_unsigned
41+
%conv = zext i64 %a to i128
42+
%conv1 = zext i64 %b to i128
43+
%mul = mul nuw i128 %conv1, %conv
44+
%shr = lshr i128 %mul, 64
45+
%conv2 = trunc i128 %shr to i64
46+
ret i64 %conv2
47+
48+
; CHECK: uhmul64 r0, r1
49+
}
50+
51+
define dso_local i64 @test_64_signed(i64 noundef %a, i64 noundef %b) {
52+
entry:
53+
; CHECK-LABEL: test_64_signed
54+
%conv = sext i64 %a to i128
55+
%conv1 = sext i64 %b to i128
56+
%mul = mul nsw i128 %conv1, %conv
57+
%shr = lshr i128 %mul, 64
58+
%conv2 = trunc i128 %shr to i64
59+
ret i64 %conv2
60+
61+
; CHECK: shmul64 r0, r1
62+
}

0 commit comments

Comments
 (0)