[llvm] r308687 - GlobalISel: stop localizer putting constants before EH_LABELs

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 20 15:58:26 PDT 2017


Author: tnorthover
Date: Thu Jul 20 15:58:26 2017
New Revision: 308687

URL: http://llvm.org/viewvc/llvm-project?rev=308687&view=rev
Log:
GlobalISel: stop localizer putting constants before EH_LABELs

If the localizer pass puts one of its constants before the label that tells the
unwinder "jump here to handle your exception" then control-flow will skip it,
leaving uninitialized registers at runtime. That's bad.

Modified:
    llvm/trunk/lib/CodeGen/GlobalISel/Localizer.cpp
    llvm/trunk/test/CodeGen/AArch64/GlobalISel/localizer.mir

Modified: llvm/trunk/lib/CodeGen/GlobalISel/Localizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/Localizer.cpp?rev=308687&r1=308686&r2=308687&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/Localizer.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/Localizer.cpp Thu Jul 20 15:58:26 2017
@@ -101,7 +101,8 @@ bool Localizer::runOnMachineFunction(Mac
           // Don't try to be smart for the insertion point.
           // There is no guarantee that the first seen use is the first
           // use in the block.
-          InsertMBB->insert(InsertMBB->getFirstNonPHI(), LocalizedMI);
+          InsertMBB->insert(InsertMBB->SkipPHIsAndLabels(InsertMBB->begin()),
+                            LocalizedMI);
 
           // Set a new register for the definition.
           unsigned NewReg =

Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/localizer.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/localizer.mir?rev=308687&r1=308686&r2=308687&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/localizer.mir (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/localizer.mir Thu Jul 20 15:58:26 2017
@@ -13,6 +13,7 @@
   define void @non_local_phi_use_followed_by_use_fi() { ret void }
   define void @float_non_local_phi_use_followed_by_use_fi() { ret void }
   define void @non_local_phi() { ret void }
+  define void @non_local_label() { ret void }
 ...
 
 ---
@@ -359,3 +360,50 @@ body:             |
     %2(s32) = G_FADD %3, %1
     G_BR %bb.1
 ...
+
+---
+# Make sure we don't insert a constant before EH_LABELs.
+# CHECK-LABEL: name: non_local_label
+name:            non_local_label
+legalized:       true
+regBankSelected: true
+tracksRegLiveness: true
+
+# CHECK:      registers:
+# Existing registers should be left untouched
+# CHECK:  - { id: 0, class: fpr, preferred-register: '' }
+#CHECK-NEXT:  - { id: 1, class: fpr, preferred-register: '' }
+#CHECK-NEXT:  - { id: 2, class: fpr, preferred-register: '' }
+#CHECK-NEXT:  - { id: 3, class: fpr, preferred-register: '' }
+# The newly created reg should be on the same regbank/regclass as its origin.
+#CHECK-NEXT:  - { id: 4, class: fpr, preferred-register: '' }
+
+registers:
+  - { id: 0, class: fpr }
+  - { id: 1, class: fpr }
+  - { id: 2, class: fpr }
+  - { id: 3, class: fpr }
+
+# CHECK:  body:
+# CHECK:    %1(s32) = G_FCONSTANT float 1.0
+
+# CHECK: bb.1:
+# CHECK: EH_LABEL
+# CHECK: %4(s32) = G_FCONSTANT float 1.0
+
+# CHECK-NEXT: %2(s32) = G_FADD %0, %4
+body:             |
+  bb.0:
+    liveins: %s0
+    successors: %bb.1
+
+    %0(s32) = COPY %s0
+    %1(s32) = G_FCONSTANT float 1.0
+
+  bb.1:
+    successors: %bb.1
+
+    EH_LABEL 1
+    %2(s32) = G_FADD %0, %1
+    G_BR %bb.1
+...




More information about the llvm-commits mailing list