Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 4f96d79

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:f06756f50e1f into amd-gfx:d2017495f111
Local branch amd-gfx d201749 Merged main:cbf931e16f6d into amd-gfx:3d027bc4e627 Remote branch main f06756f Store sysreg names in-line with their descriptors. (llvm#119157)
2 parents d201749 + f06756f commit 4f96d79

File tree

9 files changed

+175
-10
lines changed

9 files changed

+175
-10
lines changed

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 522200
19+
#define LLVM_MAIN_REVISION 522203
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ class MemDGNode final : public DGNode {
220220
void setNextNode(MemDGNode *N) { NextMemN = N; }
221221
void setPrevNode(MemDGNode *N) { PrevMemN = N; }
222222
friend class DependencyGraph; // For setNextNode(), setPrevNode().
223+
void detachFromChain() {
224+
if (PrevMemN != nullptr)
225+
PrevMemN->NextMemN = NextMemN;
226+
if (NextMemN != nullptr)
227+
NextMemN->PrevMemN = PrevMemN;
228+
PrevMemN = nullptr;
229+
NextMemN = nullptr;
230+
}
223231

224232
public:
225233
MemDGNode(Instruction *I) : DGNode(I, DGNodeID::MemDGNode) {
@@ -293,6 +301,7 @@ class DependencyGraph {
293301
Context *Ctx = nullptr;
294302
std::optional<Context::CallbackID> CreateInstrCB;
295303
std::optional<Context::CallbackID> EraseInstrCB;
304+
std::optional<Context::CallbackID> MoveInstrCB;
296305

297306
std::unique_ptr<BatchAAResults> BatchAA;
298307

@@ -343,6 +352,9 @@ class DependencyGraph {
343352
/// Called by the callbacks when instruction \p I is about to get
344353
/// deleted.
345354
void notifyEraseInstr(Instruction *I);
355+
/// Called by the callbacks when instruction \p I is about to be moved to
356+
/// \p To.
357+
void notifyMoveInstr(Instruction *I, const BBIterator &To);
346358

347359
public:
348360
/// This constructor also registers callbacks.
@@ -352,12 +364,18 @@ class DependencyGraph {
352364
[this](Instruction *I) { notifyCreateInstr(I); });
353365
EraseInstrCB = Ctx.registerEraseInstrCallback(
354366
[this](Instruction *I) { notifyEraseInstr(I); });
367+
MoveInstrCB = Ctx.registerMoveInstrCallback(
368+
[this](Instruction *I, const BBIterator &To) {
369+
notifyMoveInstr(I, To);
370+
});
355371
}
356372
~DependencyGraph() {
357373
if (CreateInstrCB)
358374
Ctx->unregisterCreateInstrCallback(*CreateInstrCB);
359375
if (EraseInstrCB)
360376
Ctx->unregisterEraseInstrCallback(*EraseInstrCB);
377+
if (MoveInstrCB)
378+
Ctx->unregisterMoveInstrCallback(*MoveInstrCB);
361379
}
362380

363381
DGNode *getNode(Instruction *I) const {

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,16 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
563563
[=](const LegalityQuery &Query) { return Query.Types[1] == v2s16; },
564564
1, s32)
565565
.minScalarOrEltIf(
566-
[=](const LegalityQuery &Query) { return Query.Types[1] == v2p0; }, 0,
567-
s64)
566+
[=](const LegalityQuery &Query) {
567+
return Query.Types[1].isPointerVector();
568+
},
569+
0, s64)
568570
.moreElementsToNextPow2(1)
569571
.clampNumElements(1, v8s8, v16s8)
570572
.clampNumElements(1, v4s16, v8s16)
571573
.clampNumElements(1, v2s32, v4s32)
572574
.clampNumElements(1, v2s64, v2s64)
575+
.clampNumElements(1, v2p0, v2p0)
573576
.customIf(isVector(0));
574577

575578
getActionDefinitionsBuilder(G_FCMP)

llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,8 @@ AArch64StringToVectorLayout(StringRef LayoutStr) {
700700

701701
namespace AArch64SysReg {
702702
struct SysReg {
703-
const char *Name;
704-
const char *AltName;
703+
const char Name[32];
704+
const char AltName[32];
705705
unsigned Encoding;
706706
bool Readable;
707707
bool Writeable;

llvm/lib/Target/ARM/Utils/ARMBaseInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ inline static unsigned ARMCondCodeFromString(StringRef CC) {
189189
// System Registers
190190
namespace ARMSysReg {
191191
struct MClassSysReg {
192-
const char *Name;
192+
const char Name[32];
193193
uint16_t M1Encoding12;
194194
uint16_t M2M3Encoding8;
195195
uint16_t Encoding;

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ int getLoadFPImm(APFloat FPImm);
452452

453453
namespace RISCVSysReg {
454454
struct SysReg {
455-
const char *Name;
456-
const char *AltName;
457-
const char *DeprecatedName;
455+
const char Name[32];
456+
const char AltName[32];
457+
const char DeprecatedName[32];
458458
unsigned Encoding;
459459
// FIXME: add these additional fields when needed.
460460
// Privilege Access: Read, Write, Read-Only.

llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,52 @@ void DependencyGraph::notifyCreateInstr(Instruction *I) {
370370
}
371371
}
372372

373+
void DependencyGraph::notifyMoveInstr(Instruction *I, const BBIterator &To) {
374+
// Early return if `I` doesn't actually move.
375+
BasicBlock *BB = To.getNodeParent();
376+
if (To != BB->end() && &*To == I->getNextNode())
377+
return;
378+
379+
// Maintain the DAGInterval.
380+
DAGInterval.notifyMoveInstr(I, To);
381+
382+
// TODO: Perhaps check if this is legal by checking the dependencies?
383+
384+
// Update the MemDGNode chain to reflect the instr movement if necessary.
385+
DGNode *N = getNodeOrNull(I);
386+
if (N == nullptr)
387+
return;
388+
MemDGNode *MemN = dyn_cast<MemDGNode>(N);
389+
if (MemN == nullptr)
390+
return;
391+
// First detach it from the existing chain.
392+
MemN->detachFromChain();
393+
// Now insert it back into the chain at the new location.
394+
if (To != BB->end()) {
395+
DGNode *ToN = getNodeOrNull(&*To);
396+
if (ToN != nullptr) {
397+
MemDGNode *PrevMemN = getMemDGNodeBefore(ToN, /*IncludingN=*/false);
398+
MemDGNode *NextMemN = getMemDGNodeAfter(ToN, /*IncludingN=*/true);
399+
MemN->PrevMemN = PrevMemN;
400+
if (PrevMemN != nullptr)
401+
PrevMemN->NextMemN = MemN;
402+
MemN->NextMemN = NextMemN;
403+
if (NextMemN != nullptr)
404+
NextMemN->PrevMemN = MemN;
405+
}
406+
} else {
407+
// MemN becomes the last instruction in the BB.
408+
auto *TermN = getNodeOrNull(BB->getTerminator());
409+
if (TermN != nullptr) {
410+
MemDGNode *PrevMemN = getMemDGNodeBefore(TermN, /*IncludingN=*/false);
411+
PrevMemN->NextMemN = MemN;
412+
MemN->PrevMemN = PrevMemN;
413+
} else {
414+
// The terminator is outside the DAG interval so do nothing.
415+
}
416+
}
417+
}
418+
373419
void DependencyGraph::notifyEraseInstr(Instruction *I) {
374420
// Update the MemDGNode chain if this is a memory node.
375421
if (auto *MemN = dyn_cast_or_null<MemDGNode>(getNodeOrNull(I))) {

llvm/test/CodeGen/AArch64/GlobalISel/legalize-cmp.mir

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,3 +541,68 @@ body: |
541541
%zext:_(s32) = G_ZEXT %2(s8)
542542
$w0 = COPY %zext(s32)
543543
RET_ReallyLR
544+
...
545+
---
546+
name: test_4xs64_ne
547+
tracksRegLiveness: true
548+
body: |
549+
bb.1:
550+
liveins:
551+
; CHECK-LABEL: name: test_4xs64_ne
552+
; CHECK: [[DEF:%[0-9]+]]:_(<2 x s64>) = G_IMPLICIT_DEF
553+
; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(<2 x s64>) = G_ICMP intpred(eq), [[DEF]](<2 x s64>), [[DEF]]
554+
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 -1
555+
; CHECK-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x s64>) = G_BUILD_VECTOR [[C]](s64), [[C]](s64)
556+
; CHECK-NEXT: [[XOR:%[0-9]+]]:_(<2 x s64>) = G_XOR [[ICMP]], [[BUILD_VECTOR]]
557+
; CHECK-NEXT: [[ICMP1:%[0-9]+]]:_(<2 x s64>) = G_ICMP intpred(eq), [[DEF]](<2 x s64>), [[DEF]]
558+
; CHECK-NEXT: [[BUILD_VECTOR1:%[0-9]+]]:_(<2 x s64>) = G_BUILD_VECTOR [[C]](s64), [[C]](s64)
559+
; CHECK-NEXT: [[XOR1:%[0-9]+]]:_(<2 x s64>) = G_XOR [[ICMP1]], [[BUILD_VECTOR1]]
560+
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
561+
; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(<2 x s32>) = G_TRUNC [[XOR]](<2 x s64>)
562+
; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(<2 x s32>) = G_TRUNC [[XOR1]](<2 x s64>)
563+
; CHECK-NEXT: [[CONCAT_VECTORS:%[0-9]+]]:_(<4 x s32>) = G_CONCAT_VECTORS [[TRUNC]](<2 x s32>), [[TRUNC1]](<2 x s32>)
564+
; CHECK-NEXT: [[EVEC:%[0-9]+]]:_(s32) = G_EXTRACT_VECTOR_ELT [[CONCAT_VECTORS]](<4 x s32>), [[C1]](s64)
565+
; CHECK-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
566+
; CHECK-NEXT: %zext:_(s32) = G_AND [[EVEC]], [[C2]]
567+
; CHECK-NEXT: $w0 = COPY %zext(s32)
568+
; CHECK-NEXT: RET_ReallyLR
569+
%vec:_(<4 x s64>) = G_IMPLICIT_DEF
570+
%cmp:_(<4 x s1>) = G_ICMP intpred(ne), %vec(<4 x s64>), %vec
571+
%1:_(s64) = G_CONSTANT i64 1
572+
%elt:_(s1) = G_EXTRACT_VECTOR_ELT %cmp(<4 x s1>), %1
573+
%zext:_(s32) = G_ZEXT %elt(s1)
574+
$w0 = COPY %zext(s32)
575+
RET_ReallyLR
576+
...
577+
---
578+
name: test_4xp0_ne
579+
tracksRegLiveness: true
580+
body: |
581+
bb.1:
582+
liveins:
583+
; CHECK-LABEL: name: test_4xp0_ne
584+
; CHECK: [[DEF:%[0-9]+]]:_(<2 x p0>) = G_IMPLICIT_DEF
585+
; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(<2 x s64>) = G_ICMP intpred(eq), [[DEF]](<2 x p0>), [[DEF]]
586+
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 -1
587+
; CHECK-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x s64>) = G_BUILD_VECTOR [[C]](s64), [[C]](s64)
588+
; CHECK-NEXT: [[XOR:%[0-9]+]]:_(<2 x s64>) = G_XOR [[ICMP]], [[BUILD_VECTOR]]
589+
; CHECK-NEXT: [[ICMP1:%[0-9]+]]:_(<2 x s64>) = G_ICMP intpred(eq), [[DEF]](<2 x p0>), [[DEF]]
590+
; CHECK-NEXT: [[BUILD_VECTOR1:%[0-9]+]]:_(<2 x s64>) = G_BUILD_VECTOR [[C]](s64), [[C]](s64)
591+
; CHECK-NEXT: [[XOR1:%[0-9]+]]:_(<2 x s64>) = G_XOR [[ICMP1]], [[BUILD_VECTOR1]]
592+
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
593+
; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(<2 x s32>) = G_TRUNC [[XOR]](<2 x s64>)
594+
; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(<2 x s32>) = G_TRUNC [[XOR1]](<2 x s64>)
595+
; CHECK-NEXT: [[CONCAT_VECTORS:%[0-9]+]]:_(<4 x s32>) = G_CONCAT_VECTORS [[TRUNC]](<2 x s32>), [[TRUNC1]](<2 x s32>)
596+
; CHECK-NEXT: [[EVEC:%[0-9]+]]:_(s32) = G_EXTRACT_VECTOR_ELT [[CONCAT_VECTORS]](<4 x s32>), [[C1]](s64)
597+
; CHECK-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
598+
; CHECK-NEXT: %zext:_(s32) = G_AND [[EVEC]], [[C2]]
599+
; CHECK-NEXT: $w0 = COPY %zext(s32)
600+
; CHECK-NEXT: RET_ReallyLR
601+
%vec:_(<4 x p0>) = G_IMPLICIT_DEF
602+
%cmp:_(<4 x s1>) = G_ICMP intpred(ne), %vec(<4 x p0>), %vec
603+
%1:_(s64) = G_CONSTANT i64 1
604+
%elt:_(s1) = G_EXTRACT_VECTOR_ELT %cmp(<4 x s1>), %1
605+
%zext:_(s32) = G_ZEXT %elt(s1)
606+
$w0 = COPY %zext(s32)
607+
RET_ReallyLR
608+
...

llvm/unittests/Transforms/Vectorize/SandboxVectorizer/DependencyGraphTest.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ define void @foo(ptr %ptr, i8 %v1, i8 %v2, i8 %v3, i8 %v4, i8 %v5) {
801801

802802
TEST_F(DependencyGraphTest, CreateInstrCallback) {
803803
parseIR(C, R"IR(
804-
define void @foo(ptr %ptr, i8 %v1, i8 %v2, i8 %v3, i8 %arg) {
804+
define void @foo(ptr %ptr, ptr noalias %ptr2, i8 %v1, i8 %v2, i8 %v3, i8 %arg) {
805805
store i8 %v1, ptr %ptr
806806
store i8 %v2, ptr %ptr
807807
store i8 %v3, ptr %ptr
@@ -893,3 +893,36 @@ define void @foo(ptr %ptr, i8 %v1, i8 %v2, i8 %v3, i8 %arg) {
893893

894894
// TODO: Check the dependencies to/from NewSN after they land.
895895
}
896+
897+
TEST_F(DependencyGraphTest, MoveInstrCallback) {
898+
parseIR(C, R"IR(
899+
define void @foo(ptr %ptr, ptr %ptr2, i8 %v1, i8 %v2, i8 %v3, i8 %arg) {
900+
%ld0 = load i8, ptr %ptr2
901+
store i8 %v1, ptr %ptr
902+
store i8 %v2, ptr %ptr
903+
store i8 %v3, ptr %ptr
904+
ret void
905+
}
906+
)IR");
907+
llvm::Function *LLVMF = &*M->getFunction("foo");
908+
sandboxir::Context Ctx(C);
909+
auto *F = Ctx.createFunction(LLVMF);
910+
auto *BB = &*F->begin();
911+
auto It = BB->begin();
912+
auto *Ld = cast<sandboxir::LoadInst>(&*It++);
913+
auto *S1 = cast<sandboxir::StoreInst>(&*It++);
914+
auto *S2 = cast<sandboxir::StoreInst>(&*It++);
915+
auto *S3 = cast<sandboxir::StoreInst>(&*It++);
916+
917+
sandboxir::DependencyGraph DAG(getAA(*LLVMF), Ctx);
918+
DAG.extend({Ld, S3});
919+
auto *LdN = cast<sandboxir::MemDGNode>(DAG.getNode(Ld));
920+
auto *S1N = cast<sandboxir::MemDGNode>(DAG.getNode(S1));
921+
auto *S2N = cast<sandboxir::MemDGNode>(DAG.getNode(S2));
922+
EXPECT_EQ(S1N->getPrevNode(), LdN);
923+
S1->moveBefore(Ld);
924+
EXPECT_EQ(S1N->getPrevNode(), nullptr);
925+
EXPECT_EQ(S1N->getNextNode(), LdN);
926+
EXPECT_EQ(LdN->getPrevNode(), S1N);
927+
EXPECT_EQ(LdN->getNextNode(), S2N);
928+
}

0 commit comments

Comments
 (0)