[llvm] 4bdc7f7 - [MC] Remove unneeded special cases from AttemptToFoldSymbolOffsetDifference

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 15 16:12:14 PDT 2023


Author: Fangrui Song
Date: 2023-06-15T16:12:10-07:00
New Revision: 4bdc7f7a331f82cca1637388cf68bdc5b32ab43b

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

LOG: [MC] Remove unneeded special cases from AttemptToFoldSymbolOffsetDifference

Added: 
    

Modified: 
    llvm/lib/MC/MCExpr.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index fc2c3ee8fdd53..46a0367a23f6f 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -619,17 +619,8 @@ static void AttemptToFoldSymbolOffsetDifference(
 
   const MCFragment *FA = SA.getFragment();
   const MCFragment *FB = SB.getFragment();
-  // If both symbols are in the same fragment, return the 
diff erence of their
-  // offsets
-  if (FA == FB && !SA.isVariable() && !SA.isUnset() && !SB.isVariable() &&
-      !SB.isUnset()) {
-    Addend += SA.getOffset() - SB.getOffset();
-    return FinalizeFolding();
-  }
-
   const MCSection &SecA = *FA->getParent();
   const MCSection &SecB = *FB->getParent();
-
   if ((&SecA != &SecB) && !Addrs)
     return;
 
@@ -654,11 +645,12 @@ static void AttemptToFoldSymbolOffsetDifference(
     // this is important when the Subtarget is changed and a new MCDataFragment
     // is created in the case of foo: instr; .arch_extension ext; instr .if . -
     // foo.
-    if (SA.isVariable() || SA.isUnset() || SB.isVariable() || SB.isUnset() ||
-        FA->getKind() != MCFragment::FT_Data ||
-        FB->getKind() != MCFragment::FT_Data ||
+    if (FA != FB && (!isa<MCDataFragment>(FA) || !isa<MCDataFragment>(FA)))
+      return;
+    if (SA.isVariable() || SB.isVariable() ||
         FA->getSubsectionNumber() != FB->getSubsectionNumber())
       return;
+
     // Try to find a constant displacement from FA to FB, add the displacement
     // between the offset in FA of SA and the offset in FB of SB.
     int64_t Displacement = SA.getOffset() - SB.getOffset();


        


More information about the llvm-commits mailing list