[llvm] de035c1 - [GlobalISel] Fix sext_inreg(load) combine to not move the originating load.

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 11 19:27:16 PST 2021


Author: Amara Emerson
Date: 2021-02-11T19:27:09-08:00
New Revision: de035c18cf76d442f1f2df5cc417bd03258edec2

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

LOG: [GlobalISel] Fix sext_inreg(load) combine to not move the originating load.

The builder was using the extend user as the insertion point, which meant that
we were incorrectly "moving" the load from its original position, and therefore
could violate memory operation ordering.

Added: 
    

Modified: 
    llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
    llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-sextload-from-sextinreg.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index 0e3357bc7bad..29b617d027a3 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -730,7 +730,7 @@ bool CombinerHelper::applySextInRegOfLoad(
   // %ld = G_SEXTLOAD %ptr (load 1)
 
   auto &MMO = **LoadDef->memoperands_begin();
-  Builder.setInstrAndDebugLoc(MI);
+  Builder.setInstrAndDebugLoc(*LoadDef);
   auto &MF = Builder.getMF();
   auto PtrInfo = MMO.getPointerInfo();
   auto *NewMMO = MF.getMachineMemOperand(&MMO, PtrInfo, ScalarSizeBits / 8);

diff  --git a/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-sextload-from-sextinreg.mir b/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-sextload-from-sextinreg.mir
index a216c5b74b35..1b8dd93d48f1 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-sextload-from-sextinreg.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-sextload-from-sextinreg.mir
@@ -24,6 +24,34 @@ body:             |
     $w0 = COPY %3(s32)
     RET_ReallyLR implicit $w0
 
+...
+---
+name:            sextload_from_inreg_across_store
+alignment:       4
+tracksRegLiveness: true
+liveins:
+  - { reg: '$x0' }
+body:             |
+  bb.1:
+    liveins: $x0
+    ; Check that the extend gets folded into the load, not the other way around, which
+    ; could cause mem dependence violations.
+    ; CHECK-LABEL: name: sextload_from_inreg_across_store
+    ; CHECK: liveins: $x0
+    ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $x0
+    ; CHECK: [[SEXTLOAD:%[0-9]+]]:_(s16) = G_SEXTLOAD [[COPY]](p0) :: (load 1, align 2)
+    ; CHECK: G_STORE [[COPY]](p0), [[COPY]](p0) :: (store 8)
+    ; CHECK: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[SEXTLOAD]](s16)
+    ; CHECK: $w0 = COPY [[ANYEXT]](s32)
+    ; CHECK: RET_ReallyLR implicit $w0
+    %0:_(p0) = COPY $x0
+    %1:_(s16) = G_LOAD %0(p0) :: (load 2)
+    G_STORE %0(p0), %0(p0) :: (store 8)
+    %2:_(s16) = G_SEXT_INREG %1, 8
+    %3:_(s32) = G_ANYEXT %2(s16)
+    $w0 = COPY %3(s32)
+    RET_ReallyLR implicit $w0
+
 ...
 ---
 name:            non_pow_2_inreg


        


More information about the llvm-commits mailing list