Skip to content

Commit cae0bf4

Browse files
committed
pre-commit test
1 parent 9bf5bf3 commit cae0bf4

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

llvm/include/llvm/Target/GlobalISel/Combine.td

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,34 @@ def funnel_shift_overshift: GICombineRule<
10401040
(apply [{ Helper.applyFunnelShiftConstantModulo(*${root}); }])
10411041
>;
10421042

1043+
// Transform: fshl x, z, y | shl x, y -> fshl x, z, y
1044+
// Transform: shl x, y | fshl x, z, y -> fshl x, z, y
1045+
// FIXME: TableGen didn't handle G_OR commutativity on its own,
1046+
// necessitating the use of !foreach to handle it manually.
1047+
def funnel_shift_or_shift_to_funnel_shift_left_frags : GICombinePatFrag<
1048+
(outs root: $dst, $out1, $out2), (ins),
1049+
!foreach(inst, [(G_OR $dst, $out1, $out2), (G_OR $dst, $out2, $out1)],
1050+
(pattern (G_FSHL $out1, $x, $z, $y), (G_SHL $out2, $x, $y), inst))>;
1051+
def funnel_shift_or_shift_to_funnel_shift_left: GICombineRule<
1052+
(defs root:$root),
1053+
(match (funnel_shift_or_shift_to_funnel_shift_left_frags $root, $out1, $out2)),
1054+
(apply (GIReplaceReg $root, $out1))
1055+
>;
1056+
1057+
// Transform: fshr z, x, y | srl x, y -> fshr z, x, y
1058+
// Transform: srl x, y | fshr z, x, y -> fshr z, x, y
1059+
// FIXME: TableGen didn't handle G_OR commutativity on its own,
1060+
// necessitating the use of !foreach to handle it manually.
1061+
def funnel_shift_or_shift_to_funnel_shift_right_frags : GICombinePatFrag<
1062+
(outs root: $dst, $out1, $out2), (ins),
1063+
!foreach(inst, [(G_OR $dst, $out1, $out2), (G_OR $dst, $out2, $out1)],
1064+
(pattern (G_FSHR $out1, $z, $x, $y), (G_LSHR $out2, $x, $y), inst))>;
1065+
def funnel_shift_or_shift_to_funnel_shift_right: GICombineRule<
1066+
(defs root:$root),
1067+
(match (funnel_shift_or_shift_to_funnel_shift_right_frags $root, $out1, $out2)),
1068+
(apply (GIReplaceReg $root, $out1))
1069+
>;
1070+
10431071
def rotate_out_of_range : GICombineRule<
10441072
(defs root:$root),
10451073
(match (wip_match_opcode G_ROTR, G_ROTL):$root,
@@ -1112,7 +1140,9 @@ def funnel_shift_combines : GICombineGroup<[funnel_shift_from_or_shift,
11121140
funnel_shift_to_rotate,
11131141
funnel_shift_right_zero,
11141142
funnel_shift_left_zero,
1115-
funnel_shift_overshift]>;
1143+
funnel_shift_overshift,
1144+
funnel_shift_or_shift_to_funnel_shift_left,
1145+
funnel_shift_or_shift_to_funnel_shift_right]>;
11161146

11171147
def bitfield_extract_from_sext_inreg : GICombineRule<
11181148
(defs root:$root, build_fn_matchinfo:$info),

llvm/test/CodeGen/RISCV/GlobalISel/shift.ll

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,55 @@ define i16 @test_shl_i48_2(i48 %x, i48 %y) {
105105
%trunc = trunc i48 %shl to i16
106106
ret i16 %trunc
107107
}
108+
109+
define i32 @test_fshl_i32(i32 %x, i32 %_, i32 %y) {
110+
; RV32-LABEL: test_fshl_i32:
111+
; RV32: # %bb.0:
112+
; RV32-NEXT: not a3, a2
113+
; RV32-NEXT: sll a0, a0, a2
114+
; RV32-NEXT: srli a1, a1, 1
115+
; RV32-NEXT: srl a1, a1, a3
116+
; RV32-NEXT: or a0, a0, a0
117+
; RV32-NEXT: or a0, a0, a1
118+
; RV32-NEXT: ret
119+
;
120+
; RV64-LABEL: test_fshl_i32:
121+
; RV64: # %bb.0:
122+
; RV64-NEXT: not a3, a2
123+
; RV64-NEXT: sllw a0, a0, a2
124+
; RV64-NEXT: srliw a1, a1, 1
125+
; RV64-NEXT: srlw a1, a1, a3
126+
; RV64-NEXT: or a0, a0, a0
127+
; RV64-NEXT: or a0, a0, a1
128+
; RV64-NEXT: ret
129+
%fshl = call i32 @llvm.fshl.i32(i32 %x, i32 %_, i32 %y)
130+
%shl = shl i32 %x, %y
131+
%or = or i32 %fshl, %shl
132+
ret i32 %or
133+
}
134+
135+
define i32 @test_fshr_i32(i32 %_, i32 %x, i32 %y) {
136+
; RV32-LABEL: test_fshr_i32:
137+
; RV32: # %bb.0:
138+
; RV32-NEXT: not a3, a2
139+
; RV32-NEXT: slli a0, a0, 1
140+
; RV32-NEXT: srl a1, a1, a2
141+
; RV32-NEXT: sll a0, a0, a3
142+
; RV32-NEXT: or a1, a1, a1
143+
; RV32-NEXT: or a0, a1, a0
144+
; RV32-NEXT: ret
145+
;
146+
; RV64-LABEL: test_fshr_i32:
147+
; RV64: # %bb.0:
148+
; RV64-NEXT: not a3, a2
149+
; RV64-NEXT: slli a0, a0, 1
150+
; RV64-NEXT: srlw a1, a1, a2
151+
; RV64-NEXT: sllw a0, a0, a3
152+
; RV64-NEXT: or a1, a1, a1
153+
; RV64-NEXT: or a0, a1, a0
154+
; RV64-NEXT: ret
155+
%fshr = call i32 @llvm.fshr.i32(i32 %_, i32 %x, i32 %y)
156+
%lshr = lshr i32 %x, %y
157+
%or = or i32 %lshr, %fshr
158+
ret i32 %or
159+
}

0 commit comments

Comments
 (0)