[PATCH] D35202: [X86] lea rdx, [rax - one] adds one instead of subtracts when one is a symbol that has been .set (PR33667)
Andrew V. Tischenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 10 08:37:36 PDT 2017
avt77 created this revision.
It's a problem in Intel syntax of asm.
https://reviews.llvm.org/D35202
Files:
lib/Target/X86/AsmParser/X86AsmParser.cpp
test/MC/X86/intel-syntax.s
Index: test/MC/X86/intel-syntax.s
===================================================================
--- test/MC/X86/intel-syntax.s
+++ test/MC/X86/intel-syntax.s
@@ -6,7 +6,19 @@
xor EAX, EAX
ret
+.set number, 33
+
_main:
+// CHECK: leaq -33(%rax), %rdx
+// CHECK: leaq -33(%rax), %rdx
+// CHECK: leaq 33(%rax), %rdx
+// CHECK: leaq 33(%rax), %rdx
+
+ lea rdx, [rax - 33]
+ lea rdx, [rax - number]
+ lea rdx, [rax + number]
+ lea rdx, [number + rax]
+
// CHECK: movl $257, -4(%rsp)
mov DWORD PTR [RSP - 4], 257
// CHECK: movl $258, 4(%rsp)
Index: lib/Target/X86/AsmParser/X86AsmParser.cpp
===================================================================
--- lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -558,7 +558,11 @@
State = IES_INTEGER;
Sym = SymRef;
SymName = SymRefName;
- IC.pushOperand(IC_IMM);
+ if (Sym->getKind() == llvm::MCExpr::Constant) {
+ auto *Constant = cast<MCConstantExpr>(SymRef);
+ IC.pushOperand(IC_IMM, Constant->getValue());
+ } else
+ IC.pushOperand(IC_IMM);
break;
}
}
@@ -1504,9 +1508,10 @@
End);
}
- if (SM.getImm() || !Disp) {
+ int64_t ImmVal = SM.getImm();
+ if (ImmVal || !Disp) {
const MCExpr *Imm = MCConstantExpr::create(SM.getImm(), getContext());
- if (Disp)
+ if (Disp && ImmVal && Disp->getKind() == llvm::MCExpr::SymbolRef)
Disp = MCBinaryExpr::createAdd(Disp, Imm, getContext());
else
Disp = Imm; // An immediate displacement only.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35202.105857.patch
Type: text/x-patch
Size: 1611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170710/f779b888/attachment.bin>
More information about the llvm-commits
mailing list