[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
Fri Jul 14 01:43:36 PDT 2017
avt77 updated this revision to Diff 106590.
avt77 added a comment.
I fixed Simon's comments.
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,18 @@
xor EAX, EAX
ret
+.set number, 33
+
_main:
+// CHECK: leaq -33(%rax), %rdx
+ lea rdx, [rax - 33]
+// CHECK: leaq -33(%rax), %rdx
+ lea rdx, [rax - number]
+// CHECK: leaq 33(%rax), %rdx
+ lea rdx, [rax + number]
+// CHECK: leaq 33(%rax), %rdx
+ 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) {
- const MCExpr *Imm = MCConstantExpr::create(SM.getImm(), getContext());
- if (Disp)
+ int64_t ImmVal = SM.getImm();
+ if (ImmVal || !Disp) {
+ const MCExpr *Imm = MCConstantExpr::create(ImmVal, getContext());
+ 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.106590.patch
Type: text/x-patch
Size: 1680 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170714/9e19b829/attachment.bin>
More information about the llvm-commits
mailing list