@@ -253,6 +253,7 @@ define void @foo(ptr noalias %ptr0, ptr noalias %ptr1, i8 %v0, i8 %v1) {
253253 %add0 = add i8 %v0, 0
254254 %add1 = add i8 %v1, 1
255255 br label %bb1
256+
256257bb1:
257258 store i8 %add0, ptr %ptr0
258259 store i8 %add1, ptr %ptr1
@@ -392,3 +393,77 @@ define void @foo(ptr %ptr) {
392393 EXPECT_TRUE (ReadyList.empty ());
393394 EXPECT_THAT (Nodes, testing::UnorderedElementsAre (L0N, RetN));
394395}
396+
397+ TEST_F (SchedulerTest, ReadyListPriorities) {
398+ parseIR (C, R"IR(
399+ define void @foo(ptr %ptr) {
400+ bb0:
401+ br label %bb1
402+
403+ bb1:
404+ %phi0 = phi i8 [0, %bb0], [1, %bb1]
405+ %phi1 = phi i8 [0, %bb0], [1, %bb1]
406+ %ld0 = load i8, ptr %ptr
407+ store i8 %ld0, ptr %ptr
408+ ret void
409+ }
410+ )IR" );
411+ llvm::Function *LLVMF = &*M->getFunction (" foo" );
412+ sandboxir::Context Ctx (C);
413+ auto *F = Ctx.createFunction (LLVMF);
414+ auto *BB1 = getBasicBlockByName (F, " bb1" );
415+ auto It = BB1->begin ();
416+ auto *Phi0 = cast<sandboxir::PHINode>(&*It++);
417+ auto *Phi1 = cast<sandboxir::PHINode>(&*It++);
418+ auto *L0 = cast<sandboxir::LoadInst>(&*It++);
419+ auto *S0 = cast<sandboxir::StoreInst>(&*It++);
420+ auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
421+
422+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx);
423+ DAG.extend ({&*BB1->begin (), BB1->getTerminator ()});
424+ auto *Phi0N = DAG.getNode (Phi0);
425+ auto *Phi1N = DAG.getNode (Phi1);
426+ auto *L0N = DAG.getNode (L0);
427+ auto *S0N = DAG.getNode (S0);
428+ auto *RetN = DAG.getNode (Ret);
429+
430+ sandboxir::ReadyListContainer ReadyList;
431+ // Check PHI vs non-PHI.
432+ ReadyList.insert (S0N);
433+ ReadyList.insert (Phi0N);
434+ EXPECT_EQ (ReadyList.pop (), Phi0N);
435+ EXPECT_EQ (ReadyList.pop (), S0N);
436+ ReadyList.insert (Phi0N);
437+ ReadyList.insert (S0N);
438+ EXPECT_EQ (ReadyList.pop (), Phi0N);
439+ EXPECT_EQ (ReadyList.pop (), S0N);
440+ // Check PHI vs terminator.
441+ ReadyList.insert (RetN);
442+ ReadyList.insert (Phi1N);
443+ EXPECT_EQ (ReadyList.pop (), Phi1N);
444+ EXPECT_EQ (ReadyList.pop (), RetN);
445+ ReadyList.insert (Phi1N);
446+ ReadyList.insert (RetN);
447+ EXPECT_EQ (ReadyList.pop (), Phi1N);
448+ EXPECT_EQ (ReadyList.pop (), RetN);
449+ // Check terminator vs non-terminator.
450+ ReadyList.insert (RetN);
451+ ReadyList.insert (L0N);
452+ EXPECT_EQ (ReadyList.pop (), L0N);
453+ EXPECT_EQ (ReadyList.pop (), RetN);
454+ ReadyList.insert (L0N);
455+ ReadyList.insert (RetN);
456+ EXPECT_EQ (ReadyList.pop (), L0N);
457+ EXPECT_EQ (ReadyList.pop (), RetN);
458+ // Check all, program order.
459+ ReadyList.insert (RetN);
460+ ReadyList.insert (L0N);
461+ ReadyList.insert (Phi1N);
462+ ReadyList.insert (S0N);
463+ ReadyList.insert (Phi0N);
464+ EXPECT_EQ (ReadyList.pop (), Phi0N);
465+ EXPECT_EQ (ReadyList.pop (), Phi1N);
466+ EXPECT_EQ (ReadyList.pop (), L0N);
467+ EXPECT_EQ (ReadyList.pop (), S0N);
468+ EXPECT_EQ (ReadyList.pop (), RetN);
469+ }
0 commit comments