Skip to content

Commit dd456da

Browse files
committed
[GlobalISel] Match G_CONSTANT from GIM_CheckLiteralInt
We represent a G_VLSHR as: %18:gpr(s32) = G_CONSTANT i32 16 %11:fpr(<4 x s32>) = G_VLSHR %1:fpr, %18:gpr(s32) not as an immediate operand %11:fpr(<4 x s32>) = G_VLSHR %1:fpr, 16 This means that certain patterns, unlike SDAG, will not match on the constant. If we use the second form then the basic patterns recognizing any constant (using ImmLeaf) do not match. When we use the first form then patterns with specific constants do not match. This makes GIM_CheckLiteralInt also match on G_CONSTANT, allowing patterns with specific constants to match. I don't have a strong preference if this should strongly work some other way. (CMLT is used because it can have a higher throughput than SSHR. The others changes are to generate less instructions).
1 parent 1d7ec60 commit dd456da

15 files changed

+319
-583
lines changed

llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,19 @@ bool GIMatchTableExecutor::executeMatchTable(
901901
if (MO.isCImm() && MO.getCImm()->equalsInt(Value))
902902
break;
903903

904+
if (MO.isReg()) {
905+
LLT Ty = MRI.getType(MO.getReg());
906+
if (Ty.getScalarSizeInBits() > 64) {
907+
if (handleReject() == RejectAndGiveUp)
908+
return false;
909+
break;
910+
}
911+
912+
Value = SignExtend64(Value, Ty.getScalarSizeInBits());
913+
if (isOperandImmEqual(MO, Value, MRI, /*Splat=*/true))
914+
break;
915+
}
916+
904917
if (handleReject() == RejectAndGiveUp)
905918
return false;
906919

llvm/test/CodeGen/AArch64/GlobalISel/combine-udiv.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ define <16 x i8> @combine_vec_udiv_nonuniform4(<16 x i8> %x) {
177177
; GISEL-NEXT: neg v2.16b, v3.16b
178178
; GISEL-NEXT: shl v3.16b, v4.16b, #7
179179
; GISEL-NEXT: ushl v1.16b, v1.16b, v2.16b
180-
; GISEL-NEXT: sshr v2.16b, v3.16b, #7
180+
; GISEL-NEXT: cmlt v2.16b, v3.16b, #0
181181
; GISEL-NEXT: bif v0.16b, v1.16b, v2.16b
182182
; GISEL-NEXT: ret
183183
%div = udiv <16 x i8> %x, <i8 -64, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
@@ -229,7 +229,7 @@ define <8 x i16> @pr38477(<8 x i16> %a0) {
229229
; GISEL-NEXT: add v1.8h, v2.8h, v1.8h
230230
; GISEL-NEXT: neg v2.8h, v4.8h
231231
; GISEL-NEXT: ushl v1.8h, v1.8h, v2.8h
232-
; GISEL-NEXT: sshr v2.8h, v3.8h, #15
232+
; GISEL-NEXT: cmlt v2.8h, v3.8h, #0
233233
; GISEL-NEXT: bif v0.16b, v1.16b, v2.16b
234234
; GISEL-NEXT: ret
235235
%1 = udiv <8 x i16> %a0, <i16 1, i16 119, i16 73, i16 -111, i16 -3, i16 118, i16 32, i16 31>

llvm/test/CodeGen/AArch64/aarch64-matrix-umull-smull.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ define void @sink_v8z16_0(ptr %p, ptr %d, i64 %n, <16 x i8> %a) {
902902
; CHECK-GI-NEXT: subs x2, x2, #8
903903
; CHECK-GI-NEXT: add x8, x8, #8
904904
; CHECK-GI-NEXT: umull v1.8h, v1.8b, v0.8b
905-
; CHECK-GI-NEXT: sshr v1.8h, v1.8h, #15
905+
; CHECK-GI-NEXT: cmlt v1.8h, v1.8h, #0
906906
; CHECK-GI-NEXT: xtn v1.8b, v1.8h
907907
; CHECK-GI-NEXT: str d1, [x0], #32
908908
; CHECK-GI-NEXT: b.ne .LBB8_1
@@ -967,8 +967,8 @@ define void @sink_v16s16_8(ptr %p, ptr %d, i64 %n, <16 x i8> %a) {
967967
; CHECK-GI-NEXT: mov d2, v1.d[1]
968968
; CHECK-GI-NEXT: smull v1.8h, v1.8b, v0.8b
969969
; CHECK-GI-NEXT: smull v2.8h, v2.8b, v0.8b
970-
; CHECK-GI-NEXT: sshr v1.8h, v1.8h, #15
971-
; CHECK-GI-NEXT: sshr v2.8h, v2.8h, #15
970+
; CHECK-GI-NEXT: cmlt v1.8h, v1.8h, #0
971+
; CHECK-GI-NEXT: cmlt v2.8h, v2.8h, #0
972972
; CHECK-GI-NEXT: uzp1 v1.16b, v1.16b, v2.16b
973973
; CHECK-GI-NEXT: str q1, [x0], #32
974974
; CHECK-GI-NEXT: b.ne .LBB9_1

0 commit comments

Comments
 (0)