[llvm] 730e8f6 - [AArch64][GlobalISel] Fix global offset folding combine inserting MIs into wrong place.

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 8 06:28:19 PDT 2023


Author: Amara Emerson
Date: 2023-09-08T06:28:12-07:00
New Revision: 730e8f659d8a3b33cb95d29eb82dd560dc95d0a2

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

LOG: [AArch64][GlobalISel] Fix global offset folding combine inserting MIs into wrong place.

Was causing use-before-def issues. Not sure how it remained undetected for so long.

Added: 
    llvm/test/CodeGen/AArch64/GlobalISel/fold-global-offsets-insertpt.mir

Modified: 
    llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp b/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp
index 81c2be03f44c2e8..cf131613802d3a7 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp
@@ -214,7 +214,7 @@ void applyFoldGlobalOffset(MachineInstr &MI, MachineRegisterInfo &MRI,
   //  %ptrN = G_PTR_ADD %offset_g, cstN - min_cst
   uint64_t Offset, MinOffset;
   std::tie(Offset, MinOffset) = MatchInfo;
-  B.setInstrAndDebugLoc(MI);
+  B.setInstrAndDebugLoc(*std::next(MI.getIterator()));
   Observer.changingInstr(MI);
   auto &GlobalOp = MI.getOperand(1);
   auto *GV = GlobalOp.getGlobal();

diff  --git a/llvm/test/CodeGen/AArch64/GlobalISel/fold-global-offsets-insertpt.mir b/llvm/test/CodeGen/AArch64/GlobalISel/fold-global-offsets-insertpt.mir
new file mode 100644
index 000000000000000..293f8cf0b952f01
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/fold-global-offsets-insertpt.mir
@@ -0,0 +1,43 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
+# RUN: llc -mtriple aarch64-apple-darwin -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s
+--- |
+  target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+  target triple = "arm64-apple-macosx13.5.0"
+
+  %struct.wibble = type <{ [500 x %struct.wobble], [500 x %struct.wobble], [500 x %struct.wobble], [500 x %struct.wobble], [500 x %struct.wobble], i32, i32, i32, i32, i32, i32, %struct.baz, float, float, float, float, float, [4 x i8] }>
+  %struct.wobble = type { [4 x float] }
+  %struct.baz = type { %struct.foo }
+  %struct.foo = type { i64, i32 }
+
+  @global = global %struct.wibble zeroinitializer
+
+  define void @wibble() {
+    ret void
+  }
+
+...
+---
+name:            wibble
+body:             |
+  bb.1:
+    ; CHECK-LABEL: name: wibble
+    ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
+    ; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @global + 40004
+    ; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
+    ; CHECK-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[GV]], [[C1]](s64)
+    ; CHECK-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<4 x s32>) = G_BUILD_VECTOR [[C]](s32), [[C]](s32), [[C]](s32), [[C]](s32)
+    ; CHECK-NEXT: G_STORE [[C]](s32), [[PTR_ADD]](p0) :: (store (s32) into `ptr getelementptr inbounds (%struct.wibble, ptr @global, i64 0, i32 10)`)
+    ; CHECK-NEXT: G_STORE [[BUILD_VECTOR]](<4 x s32>), [[GV]](p0) :: (store (<4 x s32>) into `ptr getelementptr inbounds (%struct.wibble, ptr @global, i64 0, i32 6)`, align 4)
+    ; CHECK-NEXT: RET_ReallyLR
+    %0:_(s32) = G_CONSTANT i32 0
+    %2:_(p0) = G_GLOBAL_VALUE @global
+    %3:_(s64) = G_CONSTANT i64 40020
+    %1:_(p0) = G_PTR_ADD %2, %3(s64)
+    %4:_(<4 x s32>) = G_BUILD_VECTOR %0(s32), %0(s32), %0(s32), %0(s32)
+    %6:_(s64) = G_CONSTANT i64 40004
+    %5:_(p0) = G_PTR_ADD %2, %6(s64)
+    G_STORE %0(s32), %1(p0) :: (store (s32) into `ptr getelementptr inbounds (%struct.wibble, ptr @global, i64 0, i32 10)`)
+    G_STORE %4(<4 x s32>), %5(p0) :: (store (<4 x s32>) into `ptr getelementptr inbounds (%struct.wibble, ptr @global, i64 0, i32 6)`, align 4)
+    RET_ReallyLR
+
+...


        


More information about the llvm-commits mailing list