From 75a84b1319d6f9e665ba7b27ae5bf89b7aadb540 Mon Sep 17 00:00:00 2001 From: aklkaiyan Date: Thu, 18 Jul 2024 15:10:39 +0800 Subject: [PATCH 1/3] [llvm][CodeGen] Added a new restriction for II by pragma in window scheduler --- llvm/lib/CodeGen/MachinePipeliner.cpp | 8 +- ...swp-ws-pragma-initiation-interval-fail.mir | 85 +++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp index 497e282bb97682..f97f55d2d3faa8 100644 --- a/llvm/lib/CodeGen/MachinePipeliner.cpp +++ b/llvm/lib/CodeGen/MachinePipeliner.cpp @@ -528,8 +528,12 @@ bool MachinePipeliner::useSwingModuloScheduler() { } bool MachinePipeliner::useWindowScheduler(bool Changed) { - // WindowScheduler does not work when it is off or when SwingModuloScheduler - // is successfully scheduled. + // WindowScheduler does not work for following cases: + // 1. when it is off. + // 2. when SwingModuloScheduler is successfully scheduled. + // 3. when pragma II is enabled. + if (II_setByPragma) + return false; return WindowSchedulingOption == WindowSchedulingFlag::WS_Force || (WindowSchedulingOption == WindowSchedulingFlag::WS_On && !Changed); } diff --git a/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir b/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir new file mode 100644 index 00000000000000..81dc60086ecca4 --- /dev/null +++ b/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir @@ -0,0 +1,85 @@ +# RUN: llc --march=hexagon %s -run-pass=pipeliner -debug-only=pipeliner \ +# RUN: -window-sched=force -filetype=null -verify-machineinstrs 2>&1 \ +# RUN: | FileCheck %s +# REQUIRES: asserts + +# Test that checks no window scheduler is performed if the II set by pragma was +# enabled + +# CHECK-NOT: Start analyzing II +# CHECK-NOT: Start scheduling Phis +# CHECK-NOT: Current window Offset is {{[0-9]+}} and II is {{[0-9]+}} + +--- | + define void @test_pragma_ii_fail(ptr %a0, i32 %a1) { + b0: + %v0 = icmp sgt i32 %a1, 1 + br i1 %v0, label %b1, label %b4 + + b1: ; preds = %b0 + %v1 = load i32, ptr %a0, align 4 + %v2 = add i32 %v1, 10 + %v4 = add i32 %a1, -1 + %cgep = getelementptr i32, ptr %a0, i32 1 + br label %b2 + + b2: ; preds = %b2, %b1 + %v5 = phi i32 [ %v12, %b2 ], [ %v4, %b1 ] + %v6 = phi ptr [ %cgep2, %b2 ], [ %cgep, %b1 ] + %v7 = phi i32 [ %v10, %b2 ], [ %v2, %b1 ] + store i32 %v7, ptr %v6, align 4 + %v8 = add i32 %v7, 10 + %cgep1 = getelementptr i32, ptr %v6, i32 -1 + store i32 %v8, ptr %cgep1, align 4 + %v10 = add i32 %v7, 10 + %v12 = add i32 %v5, -1 + %v13 = icmp eq i32 %v12, 0 + %cgep2 = getelementptr i32, ptr %v6, i32 1 + br i1 %v13, label %b4, label %b2, !llvm.loop !0 + + b4: ; preds = %b2, %b0 + ret void + } + + !0 = distinct !{!0, !1} + !1 = !{!"llvm.loop.pipeline.initiationinterval", i32 2} +... +--- +name: test_pragma_ii_fail +tracksRegLiveness: true +body: | + bb.0.b0: + successors: %bb.1(0x40000000), %bb.3(0x40000000) + liveins: $r0, $r1 + + %0:intregs = COPY $r1 + %1:intregs = COPY $r0 + %2:predregs = C2_cmpgti %0, 1 + J2_jumpf %2, %bb.3, implicit-def dead $pc + J2_jump %bb.1, implicit-def dead $pc + + bb.1.b1: + successors: %bb.2(0x80000000) + + %3:intregs, %4:intregs = L2_loadri_pi %1, 4 + %5:intregs = A2_addi killed %3, 10 + %6:intregs = A2_addi %0, -1 + %7:intregs = COPY %6 + J2_loop0r %bb.2, %7, implicit-def $lc0, implicit-def $sa0, implicit-def $usr + + bb.2.b2 (machine-block-address-taken): + successors: %bb.3(0x04000000), %bb.2(0x7c000000) + + %8:intregs = PHI %4, %bb.1, %9, %bb.2 + %10:intregs = PHI %5, %bb.1, %11, %bb.2 + S2_storeri_io %8, 0, %10 + %11:intregs = A2_addi %10, 10 + S2_storeri_io %8, -4, %11 + %9:intregs = A2_addi %8, 4 + ENDLOOP0 %bb.2, implicit-def $pc, implicit-def $lc0, implicit $sa0, implicit $lc0 + J2_jump %bb.3, implicit-def dead $pc + + bb.3.b4: + PS_jmpret $r31, implicit-def dead $pc + +... From e3f6adafcbeaea60157af9744e056677fbe7183d Mon Sep 17 00:00:00 2001 From: aklkaiyan Date: Mon, 22 Jul 2024 11:09:01 +0800 Subject: [PATCH 2/3] [llvm][CodeGen] Modifications made for II by pragma WS restriction based on review comments --- llvm/lib/CodeGen/MachinePipeliner.cpp | 6 +++++- .../Hexagon/swp-ws-pragma-initiation-interval-fail.mir | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp index f97f55d2d3faa8..c554c96a99721b 100644 --- a/llvm/lib/CodeGen/MachinePipeliner.cpp +++ b/llvm/lib/CodeGen/MachinePipeliner.cpp @@ -532,8 +532,12 @@ bool MachinePipeliner::useWindowScheduler(bool Changed) { // 1. when it is off. // 2. when SwingModuloScheduler is successfully scheduled. // 3. when pragma II is enabled. - if (II_setByPragma) + if (II_setByPragma) { + LLVM_DEBUG( + dbgs() << "Window scheduling is disabled when Pragma II is set.\n"); return false; + } + return WindowSchedulingOption == WindowSchedulingFlag::WS_Force || (WindowSchedulingOption == WindowSchedulingFlag::WS_On && !Changed); } diff --git a/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir b/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir index 81dc60086ecca4..b7b5d918488a93 100644 --- a/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir +++ b/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir @@ -6,9 +6,7 @@ # Test that checks no window scheduler is performed if the II set by pragma was # enabled -# CHECK-NOT: Start analyzing II -# CHECK-NOT: Start scheduling Phis -# CHECK-NOT: Current window Offset is {{[0-9]+}} and II is {{[0-9]+}} +# CHECK: Window scheduling is disabled when Pragma II is set. --- | define void @test_pragma_ii_fail(ptr %a0, i32 %a1) { From 77ace75295ff89046f28cbd5171122dff106e976 Mon Sep 17 00:00:00 2001 From: aklkaiyan Date: Mon, 22 Jul 2024 16:47:00 +0800 Subject: [PATCH 3/3] [llvm][CodeGen] Modifications made for II by pragma WS restriction based on review comments #2 --- llvm/lib/CodeGen/MachinePipeliner.cpp | 4 ++-- .../Hexagon/swp-ws-pragma-initiation-interval-fail.mir | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp index c554c96a99721b..5c68711ff61938 100644 --- a/llvm/lib/CodeGen/MachinePipeliner.cpp +++ b/llvm/lib/CodeGen/MachinePipeliner.cpp @@ -533,8 +533,8 @@ bool MachinePipeliner::useWindowScheduler(bool Changed) { // 2. when SwingModuloScheduler is successfully scheduled. // 3. when pragma II is enabled. if (II_setByPragma) { - LLVM_DEBUG( - dbgs() << "Window scheduling is disabled when Pragma II is set.\n"); + LLVM_DEBUG(dbgs() << "Window scheduling is disabled when " + "llvm.loop.pipeline.initiationinterval is set.\n"); return false; } diff --git a/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir b/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir index b7b5d918488a93..6e69a76290fb1d 100644 --- a/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir +++ b/llvm/test/CodeGen/Hexagon/swp-ws-pragma-initiation-interval-fail.mir @@ -6,7 +6,7 @@ # Test that checks no window scheduler is performed if the II set by pragma was # enabled -# CHECK: Window scheduling is disabled when Pragma II is set. +# CHECK: Window scheduling is disabled when llvm.loop.pipeline.initiationinterval is set. --- | define void @test_pragma_ii_fail(ptr %a0, i32 %a1) {