OSDN Git Service

[Hexagon] Don't expand mux instructions with both sources identical
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Mon, 31 Oct 2016 15:45:09 +0000 (15:45 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Mon, 31 Oct 2016 15:45:09 +0000 (15:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285588 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Hexagon/HexagonExpandCondsets.cpp
test/CodeGen/Hexagon/expand-condsets-same-inputs.mir [new file with mode: 0644]

index abb7810..baa3b8b 100644 (file)
@@ -614,13 +614,31 @@ bool HexagonExpandCondsets::split(MachineInstr &MI,
   bool ReadUndef = MD.isUndef();
   MachineBasicBlock::iterator At = MI;
 
+  // If this is a mux of the same register, just replace it with COPY.
+  // Ideally, this would happen earlier, so that register coalescing would
+  // see it.
+  MachineOperand &ST = MI.getOperand(2);
+  MachineOperand &SF = MI.getOperand(3);
+  if (ST.isReg() && SF.isReg()) {
+    RegisterRef RT(ST);
+    if (RT == RegisterRef(SF)) {
+      MI.setDesc(HII->get(TargetOpcode::COPY));
+      unsigned S = getRegState(ST);
+      while (MI.getNumOperands() > 1)
+        MI.RemoveOperand(MI.getNumOperands()-1);
+      MachineFunction &MF = *MI.getParent()->getParent();
+      MachineInstrBuilder(MF, MI).addReg(RT.Reg, S, RT.Sub);
+      return true;
+    }
+  }
+
   // First, create the two invididual conditional transfers, and add each
   // of them to the live intervals information. Do that first and then remove
   // the old instruction from live intervals.
   MachineInstr *TfrT =
-      genCondTfrFor(MI.getOperand(2), At, DR, DSR, MP, true, ReadUndef, false);
+      genCondTfrFor(ST, At, DR, DSR, MP, true, ReadUndef, false);
   MachineInstr *TfrF =
-      genCondTfrFor(MI.getOperand(3), At, DR, DSR, MP, false, ReadUndef, true);
+      genCondTfrFor(SF, At, DR, DSR, MP, false, ReadUndef, true);
   LIS->InsertMachineInstrInMaps(*TfrT);
   LIS->InsertMachineInstrInMaps(*TfrF);
 
diff --git a/test/CodeGen/Hexagon/expand-condsets-same-inputs.mir b/test/CodeGen/Hexagon/expand-condsets-same-inputs.mir
new file mode 100644 (file)
index 0000000..83938d1
--- /dev/null
@@ -0,0 +1,32 @@
+# RUN: llc -march=hexagon -run-pass expand-condsets -expand-condsets-coa-limit=0 -o - %s -verify-machineinstrs | FileCheck %s
+
+# CHECK-LABEL: name: fred
+
+--- |
+  define void @fred() { ret void }
+
+...
+---
+
+name: fred
+tracksRegLiveness: true
+registers:
+  - { id: 0, class: predregs }
+  - { id: 1, class: intregs }
+  - { id: 2, class: intregs }
+  - { id: 3, class: intregs }
+
+body: |
+  bb.0:
+    liveins: %r0, %r1, %r2, %p0
+        %0 = COPY %p0
+        %0 = COPY %p0   ; Cheat: convince MIR parser that this is not SSA.
+        %1 = COPY %r1
+        ; Make sure we do not expand/predicate a mux with identical inputs.
+        ; CHECK-NOT: A2_paddit
+        %2 = A2_addi %1, 1
+        %3 = C2_mux %0, killed %2, %2
+        %r0 = COPY %3
+
+...
+