<div dir="ltr">On 11 December 2013 14:05, Sasa Stankovic <span dir="ltr"><<a href="mailto:Sasa.Stankovic@rt-rk.com" target="_blank">Sasa.Stankovic@rt-rk.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">+      // Check for expressions %hi(tmp) and %lo(tmp), where tmp = sym1-sym2.<br>
</blockquote></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">+      if (Target.getSymA() != NULL && Target.getSymA()->getSymbol().isVariable()<br>
+          && Target.getSymB() == NULL && Target.getConstant() == 0) {<br>+        const MCExpr *SymValue = Target.getSymA()->getSymbol()<br>+                                       .getVariableValue();<br>
+        const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(SymValue);<br>+<br>+        if (BE && BE->getOpcode() == MCBinaryExpr::Sub) {<br>+          const MCSymbolRefExpr *LHS = dyn_cast<MCSymbolRefExpr>(BE->getLHS());<br>
+          const MCSymbolRefExpr *RHS = dyn_cast<MCSymbolRefExpr>(BE->getRHS());<br>+          if (LHS != NULL && LHS->getSymbol().isDefined()<br>+              && RHS != NULL && RHS->getSymbol().isDefined()) {<br>
+            // Don't emit relocation for expressions %hi(tmp) and %lo(tmp),<br>+            // where tmp = sym1-sym2.<br>+            IsResolved = true;<br>+<br>+            // Calculate symbol value.<br>+            uint64_t Value1 =<br>
+              Layout.getSymbolOffset(&Asm.getSymbolData(LHS->getSymbol()));<br>+            uint64_t Value2 =<br>+              Layout.getSymbolOffset(&Asm.getSymbolData(RHS->getSymbol()));<br>+            Value = Value1 - Value2;<br>
+          }<br>+        }<br>+      }</blockquote><div><br></div><div>I think you shouldn't need to add code for evaluating a Sub expression to a MIPS-specific file (as I commented on an earlier version of this change at <a href="https://codereview.chromium.org/27690005/diff/188001/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp#newcode116">https://codereview.chromium.org/27690005/diff/188001/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp#newcode116</a>).</div>
<div><br></div><div>There is already code in the architecture-independent part of MC for evaluating expressions that you should be able to reuse.  For example, subtractions like the following already work on MIPS:</div><div>
<br></div><div>.long label2 - label1</div><div>label2:</div><div>.fill 0x54321</div><div>label1:</div><div><br></div><div>The code for evaluating that lives in AttemptToFoldSymbolOffsetDifference() in MCExpr.cpp, which calls getSymbolOffset() like your patch does.</div>
<div><br></div><div>There's also a bug in your patch:  it doesn't check whether the symbols being subtracted are in the same section, so I think it would give incorrect output if the symbols were in different sections.</div>
<div><br></div><div>Cheers,</div><div>Mark</div><div><br></div></div></div>