OSDN Git Service

[Hexagon] Setting sign mismatch flag on expression instead of using bit tricks.
authorColin LeMahieu <colinl@codeaurora.org>
Mon, 29 Feb 2016 19:17:56 +0000 (19:17 +0000)
committerColin LeMahieu <colinl@codeaurora.org>
Mon, 29 Feb 2016 19:17:56 +0000 (19:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262243 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp
lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp
lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.h

index 44d1dd6..89340eb 100644 (file)
@@ -361,20 +361,17 @@ public:
 
   void addSignedImmOperands(MCInst &Inst, unsigned N) const {
     assert(N == 1 && "Invalid number of operands!");
-    MCExpr const *Expr = getImm();
+    HexagonMCExpr *Expr =
+        const_cast<HexagonMCExpr *>(cast<HexagonMCExpr>(getImm()));
     int64_t Value;
     if (!Expr->evaluateAsAbsolute(Value)) {
       Inst.addOperand(MCOperand::createExpr(Expr));
       return;
     }
-    int64_t Extended = SignExtend64 (Value, 32);
-    if ((Extended < 0) == (Value < 0)) {
-      Inst.addOperand(MCOperand::createExpr(Expr));
-      return;
-    }
-    // Flip bit 33 to signal signed unsigned mismatch
-    Extended ^= 0x100000000;
-    Inst.addOperand(MCOperand::createImm(Extended));
+    int64_t Extended = SignExtend64(Value, 32);
+    if ((Extended < 0) != (Value < 0))
+      Expr->setSignMismatch();
+    Inst.addOperand(MCOperand::createExpr(Expr));
   }
 
   void addf32ExtOperands(MCInst &Inst, unsigned N) const {
@@ -763,17 +760,15 @@ void HexagonAsmParser::canonicalizeImmediates(MCInst &MCI) {
   for (MCOperand &I : MCI)
     if (I.isImm()) {
       int64_t Value (I.getImm());
-      if ((Value & 0x100000000) != (Value & 0x80000000)) {
-        // Detect flipped bit 33 wrt bit 32 and signal warning
-        Value ^= 0x100000000;
-        if (WarnSignedMismatch)
-          Warning (MCI.getLoc(), "Signed/Unsigned mismatch");
-      }
       NewInst.addOperand(MCOperand::createExpr(HexagonMCExpr::create(
           MCConstantExpr::create(Value, getContext()), getContext())));
     }
-    else
+    else {
+      if (I.isExpr() && cast<HexagonMCExpr>(I.getExpr())->signMismatch() &&
+          WarnSignedMismatch)
+        Warning (MCI.getLoc(), "Signed/Unsigned mismatch");
       NewInst.addOperand(I);
+    }
   MCI = NewInst;
 }
 
index 8a83e7b..329c361 100644 (file)
@@ -67,3 +67,11 @@ HexagonMCExpr::HexagonMCExpr(MCExpr const *Expr)
 void HexagonMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
   Expr->print(OS, MAI);
 }
+
+void HexagonMCExpr::setSignMismatch(bool Val) {
+  SignMismatch = Val;
+}
+
+bool HexagonMCExpr::signMismatch() const {
+  return SignMismatch;
+}
\ No newline at end of file
index 1396f2d..bca40cf 100644 (file)
@@ -31,6 +31,8 @@ public:
   bool mustNotExtend() const;
   void setS23_2_reloc(bool Val = true);
   bool s23_2_reloc() const;
+  void setSignMismatch(bool Val = true);
+  bool signMismatch() const;
 
 private:
   HexagonMCExpr(MCExpr const *Expr);
@@ -38,6 +40,7 @@ private:
   bool MustNotExtend;
   bool MustExtend;
   bool S23_2_reloc;
+  bool SignMismatch;
 };
 } // end namespace llvm