[llvm] 261cbe9 - [RISCV] Fix Machine Outliner jump table handling.

Yvan Roux via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 8 22:32:40 PDT 2021


Author: Yvan Roux
Date: 2021-09-09T07:32:30+02:00
New Revision: 261cbe98c38f8c1ee1a482fe76511110e790f58a

URL: https://github.com/llvm/llvm-project/commit/261cbe98c38f8c1ee1a482fe76511110e790f58a
DIFF: https://github.com/llvm/llvm-project/commit/261cbe98c38f8c1ee1a482fe76511110e790f58a.diff

LOG: [RISCV] Fix Machine Outliner jump table handling.

Don't outline machine instructions which are using jump table indexes
since they are materialized as local labels (like the already handled
case of constant pools).

Reviewed By: paquette

Differential Revision: https://reviews.llvm.org/D109436

Added: 
    llvm/test/CodeGen/RISCV/machineoutliner-jumptable.mir

Modified: 
    llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index c216662a604f1..6c745a9a48418 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -1139,7 +1139,7 @@ RISCVInstrInfo::getOutliningType(MachineBasicBlock::iterator &MBBI,
 
   // Make sure the operands don't reference something unsafe.
   for (const auto &MO : MI.operands())
-    if (MO.isMBB() || MO.isBlockAddress() || MO.isCPI())
+    if (MO.isMBB() || MO.isBlockAddress() || MO.isCPI() || MO.isJTI())
       return outliner::InstrType::Illegal;
 
   // Don't allow instructions which won't be materialized to impact outlining

diff  --git a/llvm/test/CodeGen/RISCV/machineoutliner-jumptable.mir b/llvm/test/CodeGen/RISCV/machineoutliner-jumptable.mir
new file mode 100644
index 0000000000000..885db0aa5023c
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/machineoutliner-jumptable.mir
@@ -0,0 +1,65 @@
+# RUN: llc -march=riscv32 -x mir -run-pass=machine-outliner -simplify-mir -verify-machineinstrs < %s \
+# RUN: | FileCheck -check-prefix=RV32I-MO %s
+# RUN: llc -march=riscv64 -x mir -run-pass=machine-outliner -simplify-mir -verify-machineinstrs < %s \
+# RUN: | FileCheck -check-prefix=RV64I-MO %s
+
+--- |
+  ; Cannot outline instructions with jump-table index operands
+  define i32 @foo(i32 %a, i32 %b) #0 { ret i32 0 }
+
+...
+---
+name:            foo
+tracksRegLiveness: true
+jumpTable:
+  kind:            block-address
+  entries:
+    - id:              0
+      blocks:          [ '%bb.0', '%bb.1', '%bb.2', '%bb.3' ]
+body:             |
+  bb.0:
+    liveins: $x10, $x11
+    ; RV32I-MO-LABEL: name: foo
+    ; RV32I-MO: $x5 = PseudoCALLReg {{.*}} @OUTLINED_FUNCTION_0
+    ; RV32I-MO: $x12 = LUI target-flags(riscv-hi) %jump-table.0
+    ; RV32I-MO: $x12 = ADDI $x12, target-flags(riscv-lo) %jump-table.0
+    ;
+    ; RV64I-MO-LABEL: name: foo
+    ; RV64I-MO: $x5 = PseudoCALLReg {{.*}} @OUTLINED_FUNCTION_0
+    ; RV64I-MO: $x12 = LUI target-flags(riscv-hi) %jump-table.0
+    ; RV64I-MO: $x12 = ADDI $x12, target-flags(riscv-lo) %jump-table.0
+
+    $x11 = ORI $x11, 1023
+    $x12 = ADDI $x10, 17
+    $x11 = AND $x12, $x11
+    $x10 = SUB $x10, $x11
+    $x12 = LUI target-flags(riscv-hi) %jump-table.0
+    $x12 = ADDI $x12, target-flags(riscv-lo) %jump-table.0
+    PseudoBR %bb.3
+
+  bb.1:
+    liveins: $x10, $x11
+
+    $x11 = ORI $x11, 1023
+    $x12 = ADDI $x10, 17
+    $x11 = AND $x12, $x11
+    $x10 = SUB $x10, $x11
+    $x12 = LUI target-flags(riscv-hi) %jump-table.0
+    $x12 = ADDI $x12, target-flags(riscv-lo) %jump-table.0
+    PseudoBR %bb.3
+
+  bb.2:
+    liveins: $x10, $x11
+
+    $x11 = ORI $x11, 1023
+    $x12 = ADDI $x10, 17
+    $x11 = AND $x12, $x11
+    $x10 = SUB $x10, $x11
+    $x12 = LUI target-flags(riscv-hi) %jump-table.0
+    $x12 = ADDI $x12, target-flags(riscv-lo) %jump-table.0
+    PseudoBR %bb.3
+
+  bb.3:
+    PseudoRET
+
+...


        


More information about the llvm-commits mailing list