[llvm] c437412 - [LoongArch] Override TargetLowering::isOffsetFoldingLegal()

Weining Lu via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 10 20:29:11 PDT 2022


Author: wanglei
Date: 2022-08-11T11:26:54+08:00
New Revision: c437412fbc1e616d623271cfca03bce009fd50f3

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

LOG: [LoongArch] Override TargetLowering::isOffsetFoldingLegal()

This patch disable GlobalAddress+Offset folding.

Differential Revision: https://reviews.llvm.org/D131491

Added: 
    

Modified: 
    llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
    llvm/lib/Target/LoongArch/LoongArchISelLowering.h
    llvm/test/CodeGen/LoongArch/ir-instruction/load-store.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 70ea5b65a816e..9900123966793 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -132,6 +132,15 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
   setTargetDAGCombine(ISD::SRL);
 }
 
+bool LoongArchTargetLowering::isOffsetFoldingLegal(
+    const GlobalAddressSDNode *GA) const {
+  // In order to maximise the opportunity for common subexpression elimination,
+  // keep a separate ADD node for the global address offset instead of folding
+  // it in the global address node. Later peephole optimisations may choose to
+  // fold it back in when profitable.
+  return false;
+}
+
 SDValue LoongArchTargetLowering::LowerOperation(SDValue Op,
                                                 SelectionDAG &DAG) const {
   switch (Op.getOpcode()) {

diff  --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.h b/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
index 3944d76c31b2b..a10235d3b964e 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
@@ -64,6 +64,8 @@ class LoongArchTargetLowering : public TargetLowering {
 
   const LoongArchSubtarget &getSubtarget() const { return Subtarget; }
 
+  bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
+
   // Provide custom lowering hooks for some operations.
   SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
   void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,

diff  --git a/llvm/test/CodeGen/LoongArch/ir-instruction/load-store.ll b/llvm/test/CodeGen/LoongArch/ir-instruction/load-store.ll
index 12546b6a4151a..4564b8ed1c005 100644
--- a/llvm/test/CodeGen/LoongArch/ir-instruction/load-store.ll
+++ b/llvm/test/CodeGen/LoongArch/ir-instruction/load-store.ll
@@ -45,8 +45,8 @@ define i32 @load_store_global_array(i32 %a) nounwind {
 ; LA32PIC-NEXT:     addi.w $a2, $a1, .Larr$local
 ; LA32-NEXT:        ld.w $a1, $a2, 0
 ; LA32-NEXT:        st.w $a0, $a2, 0
-; LA32NOPIC-NEXT:   ld.w $a3, $a2, 0
-; LA32NOPIC-NEXT:   st.w $a0, $a2, 0
+; LA32NOPIC-NEXT:   ld.w $a3, $a2, 36
+; LA32NOPIC-NEXT:   st.w $a0, $a2, 36
 ; LA32PIC-NEXT:     ld.w $a3, $a2, 36
 ; LA32PIC-NEXT:     st.w $a0, $a2, 36
 
@@ -56,8 +56,8 @@ define i32 @load_store_global_array(i32 %a) nounwind {
 ; LA64PIC-NEXT:     addi.d $a2, $a1, .Larr$local
 ; LA64-NEXT:        ld.w $a1, $a2, 0
 ; LA64-NEXT:        st.w $a0, $a2, 0
-; LA64NOPIC-NEXT:   ld.w $a3, $a2, 0
-; LA64NOPIC-NEXT:   st.w $a0, $a2, 0
+; LA64NOPIC-NEXT:   ld.w $a3, $a2, 36
+; LA64NOPIC-NEXT:   st.w $a0, $a2, 36
 ; LA64PIC-NEXT:     ld.w $a3, $a2, 36
 ; LA64PIC-NEXT:     st.w $a0, $a2, 36
 


        


More information about the llvm-commits mailing list