From: Reid Kleckner Date: Mon, 4 May 2015 23:22:36 +0000 (+0000) Subject: [X86] Fix assertion while DAG combining offsets and ExternalSymbols X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c5315e5d05697dd65a4d715356355e3ca66614a1;p=oota-llvm.git [X86] Fix assertion while DAG combining offsets and ExternalSymbols ExternalSymbol nodes do not contain offsets, unlike GlobalValue nodes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236471 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp index ca1a30c05cc..c7b769585c1 100644 --- a/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -603,6 +603,9 @@ static bool isDispSafeForFrameIndex(int64_t Val) { bool X86DAGToDAGISel::FoldOffsetIntoAddress(uint64_t Offset, X86ISelAddressMode &AM) { + // Cannot combine ExternalSymbol displacements with integer offsets. + if (Offset != 0 && AM.ES) + return true; int64_t Val = AM.Disp + Offset; CodeModel::Model M = TM.getCodeModel(); if (Subtarget->is64Bit()) { @@ -1009,7 +1012,7 @@ bool X86DAGToDAGISel::MatchAddressRecursively(SDValue N, X86ISelAddressMode &AM, switch (N.getOpcode()) { default: break; case ISD::FRAME_ALLOC_RECOVER: { - if (!AM.hasSymbolicDisplacement()) + if (!AM.hasSymbolicDisplacement() && AM.Disp == 0) if (const auto *ESNode = dyn_cast(N.getOperand(0))) if (ESNode->getOpcode() == ISD::TargetExternalSymbol) { // Use the symbol and don't prefix it. diff --git a/test/CodeGen/X86/frameescape.ll b/test/CodeGen/X86/frameescape.ll index 098b6162e82..00bc55d2487 100644 --- a/test/CodeGen/X86/frameescape.ll +++ b/test/CodeGen/X86/frameescape.ll @@ -18,6 +18,9 @@ define void @print_framealloc_from_fp(i8* %fp) { %b.val = load i32, i32* %b call i32 (i8*, ...) @printf(i8* getelementptr ([10 x i8], [10 x i8]* @str, i32 0, i32 0), i32 %b.val) store i32 42, i32* %b + %b2 = getelementptr i32, i32* %b, i32 1 + %b2.val = load i32, i32* %b2 + call i32 (i8*, ...) @printf(i8* getelementptr ([10 x i8], [10 x i8]* @str, i32 0, i32 0), i32 %b2.val) ret void } @@ -46,13 +49,18 @@ define void @print_framealloc_from_fp(i8* %fp) { ; X86: movl $_str, (%esp) ; X86: calll _printf ; X86: movl $42, Lalloc_func$frame_escape_1(%esi) +; X86: movl $4, %eax +; X86: movl Lalloc_func$frame_escape_1(%esi,%eax), %eax +; X86: movl %eax, 4(%esp) +; X86: movl $_str, (%esp) +; X86: calll _printf ; X86: addl $8, %esp ; X86: popl %esi ; X86: retl define void @alloc_func() { %a = alloca i32 - %b = alloca i32 + %b = alloca i32, i32 2 call void (...) @llvm.frameescape(i32* %a, i32* %b) store i32 42, i32* %a store i32 13, i32* %b @@ -67,9 +75,9 @@ define void @alloc_func() { ; X64: leaq 48(%rsp), %rbp ; X64: .seh_setframe 5, 48 ; X64: .Lalloc_func$frame_escape_0 = 44 -; X64: .Lalloc_func$frame_escape_1 = 40 +; X64: .Lalloc_func$frame_escape_1 = 36 ; X64: movl $42, -4(%rbp) -; X64: movl $13, -8(%rbp) +; X64: movl $13, -12(%rbp) ; X64: leaq -48(%rbp), %rcx ; X64: callq print_framealloc_from_fp ; X64: retq @@ -77,14 +85,14 @@ define void @alloc_func() { ; X86-LABEL: alloc_func: ; X86: pushl %ebp ; X86: movl %esp, %ebp -; X86: subl $12, %esp +; X86: subl $16, %esp ; X86: Lalloc_func$frame_escape_0 = -4 -; X86: Lalloc_func$frame_escape_1 = -8 +; X86: Lalloc_func$frame_escape_1 = -12 ; X86: movl $42, -4(%ebp) -; X86: movl $13, -8(%ebp) +; X86: movl $13, -12(%ebp) ; X86: movl %ebp, (%esp) ; X86: calll _print_framealloc_from_fp -; X86: addl $12, %esp +; X86: addl $16, %esp ; X86: popl %ebp ; X86: retl @@ -116,3 +124,5 @@ define void @alloc_func_no_frameaddr() { ; X64: callq print_framealloc_from_fp ; X64: addq $40, %rsp ; X64: retq + +; X86-LABEL: alloc_func_no_frameaddr: