[llvm] r296551 - [GlobalISel] Replace all combined G_EXTRACT uses.

Ahmed Bougacha via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 28 16:43:39 PST 2017


Author: ab
Date: Tue Feb 28 18:43:39 2017
New Revision: 296551

URL: http://llvm.org/viewvc/llvm-project?rev=296551&view=rev
Log:
[GlobalISel] Replace all combined G_EXTRACT uses.

Iterating on the use-list we're modifying doesn't work: after the first
iteration, the use-list iterator will point to a MachineOperand
referencing the new register.  This caused us to skip the other uses to
replace.

Instead, use MRI.replaceRegWith(), which accounts for this behavior.

Modified:
    llvm/trunk/lib/CodeGen/GlobalISel/Legalizer.cpp
    llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-combines.mir

Modified: llvm/trunk/lib/CodeGen/GlobalISel/Legalizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/Legalizer.cpp?rev=296551&r1=296550&r2=296551&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/Legalizer.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/Legalizer.cpp Tue Feb 28 18:43:39 2017
@@ -94,10 +94,7 @@ bool Legalizer::combineExtracts(MachineI
            "unexpected physical register in G_SEQUENCE");
 
     // Finally we can replace the uses.
-    for (auto &Use : MRI.use_operands(ExtractReg)) {
-      Changed = true;
-      Use.setReg(OrigReg);
-    }
+    MRI.replaceRegWith(ExtractReg, OrigReg);
   }
 
   if (AllDefsReplaced) {

Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-combines.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-combines.mir?rev=296551&r1=296550&r2=296551&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-combines.mir (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-combines.mir Tue Feb 28 18:43:39 2017
@@ -8,6 +8,7 @@
   define void @test_combines_3() { ret void }
   define void @test_combines_4() { ret void }
   define void @test_combines_5() { ret void }
+  define void @test_combines_6() { ret void }
 ...
 
 ---
@@ -107,3 +108,24 @@ body: |
     %4:_(s32) = G_EXTRACT %2, 32
     %5:_(s32) = G_ADD %3, %4
 ...
+
+---
+name:            test_combines_6
+body: |
+  bb.0:
+    liveins: %w0
+
+    ; CHECK-LABEL: name: test_combines_6
+    ; CHECK: %0(s32) = COPY %w0
+    %0:_(s32) = COPY %w0
+
+    ; Check that we replace all the uses of a G_EXTRACT.
+    ; CHECK-NOT: G_SEQUENCE
+    ; CHECK-NOT: G_EXTRACT
+    ; CHECK: %3(s32) = G_MUL %0, %0
+    ; CHECK: %4(s32) = G_ADD %0, %3
+    %1:_(s32) = G_SEQUENCE %0, 0
+    %2:_(s32) = G_EXTRACT %1, 0
+    %3:_(s32) = G_MUL %2, %2
+    %4:_(s32) = G_ADD %2, %3
+...




More information about the llvm-commits mailing list