[llvm-commits] [llvm] r96064 - in /llvm/trunk: lib/MC/MCParser/AsmParser.cpp test/MC/AsmParser/X86/x86_32-new-encoder.s test/MC/AsmParser/X86/x86_operands.s test/MC/AsmParser/conditional_asm.s
Daniel Dunbar
daniel at zuster.org
Fri Feb 12 17:28:08 PST 2010
Author: ddunbar
Date: Fri Feb 12 19:28:07 2010
New Revision: 96064
URL: http://llvm.org/viewvc/llvm-project?rev=96064&view=rev
Log:
MC/AsmParser: Attempt to constant fold expressions up-front. This ensures we avoid fixups for obvious cases like '-(16)'.
Modified:
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/test/MC/AsmParser/X86/x86_32-new-encoder.s
llvm/trunk/test/MC/AsmParser/X86/x86_operands.s
llvm/trunk/test/MC/AsmParser/conditional_asm.s
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=96064&r1=96063&r2=96064&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Fri Feb 12 19:28:07 2010
@@ -325,9 +325,17 @@
/// expr ::= primaryexpr
///
bool AsmParser::ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) {
+ // Parse the expression.
Res = 0;
- return ParsePrimaryExpr(Res, EndLoc) ||
- ParseBinOpRHS(1, Res, EndLoc);
+ if (ParsePrimaryExpr(Res, EndLoc) || ParseBinOpRHS(1, Res, EndLoc))
+ return true;
+
+ // Try to constant fold it up front, if possible.
+ int64_t Value;
+ if (Res->EvaluateAsAbsolute(Value))
+ Res = MCConstantExpr::Create(Value, getContext());
+
+ return false;
}
bool AsmParser::ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) {
Modified: llvm/trunk/test/MC/AsmParser/X86/x86_32-new-encoder.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/X86/x86_32-new-encoder.s?rev=96064&r1=96063&r2=96064&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/X86/x86_32-new-encoder.s (original)
+++ llvm/trunk/test/MC/AsmParser/X86/x86_32-new-encoder.s Fri Feb 12 19:28:07 2010
@@ -28,3 +28,9 @@
swapgs
// CHECK: swapgs
// CHECK: encoding: [0x0f,0x01,0xf8]
+
+// CHECK: movl %eax, 16(%ebp) # encoding: [0x89,0x45,0x10]
+ movl %eax, 16(%ebp)
+// CHECK: movl %eax, -16(%ebp) # encoding: [0x89,0x45,0xf0]
+ movl %eax, -16(%ebp)
+
Modified: llvm/trunk/test/MC/AsmParser/X86/x86_operands.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/X86/x86_operands.s?rev=96064&r1=96063&r2=96064&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/X86/x86_operands.s (original)
+++ llvm/trunk/test/MC/AsmParser/X86/x86_operands.s Fri Feb 12 19:28:07 2010
@@ -5,28 +5,28 @@
# Immediates
# CHECK: addl $1, %eax
addl $1, %eax
-# CHECK: addl $1+2, %eax
+# CHECK: addl $3, %eax
addl $(1+2), %eax
# CHECK: addl $a, %eax
addl $a, %eax
-# CHECK: addl $1+2, %eax
+# CHECK: addl $3, %eax
addl $1 + 2, %eax
# Disambiguation
- # FIXME: Add back when we can match this.
- #addl $1, 4+4
- # FIXME: Add back when we can match this.
- #addl $1, (4+4)
-# CHECK: addl $1, 4+4(%eax)
+# CHECK: addl $1, 8
+ addl $1, 4+4
+# CHECK: addl $1, 8
+ addl $1, (4+4)
+# CHECK: addl $1, 8(%eax)
addl $1, 4+4(%eax)
-# CHECK: addl $1, 4+4(%eax)
+# CHECK: addl $1, 8(%eax)
addl $1, (4+4)(%eax)
# CHECK: addl $1, 8(%eax)
addl $1, 8(%eax)
# CHECK: addl $1, (%eax)
addl $1, (%eax)
-# CHECK: addl $1, 4+4(,%eax)
+# CHECK: addl $1, 8(,%eax)
addl $1, (4+4)(,%eax)
# Indirect Memory Operands
Modified: llvm/trunk/test/MC/AsmParser/conditional_asm.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/conditional_asm.s?rev=96064&r1=96063&r2=96064&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/conditional_asm.s (original)
+++ llvm/trunk/test/MC/AsmParser/conditional_asm.s Fri Feb 12 19:28:07 2010
@@ -1,6 +1,6 @@
# RUN: llvm-mc -triple i386-unknown-unknown %s -I %p | FileCheck %s
-# CHECK: .byte 1+1
+# CHECK: .byte 2
.if 1+2
.if 1-1
.byte 1
More information about the llvm-commits
mailing list