From 43f44aa16099d94402862f20eea10f405a7e6029 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 1 Nov 2009 03:25:03 +0000 Subject: [PATCH] improve x86 codegen support for blockaddress. We now compile the testcase into: _test1: ## @test1 ## BB#0: ## %entry leaq L_test1_bb6(%rip), %rax jmpq *%rax L_test1_bb: ## Address Taken LBB1_1: ## %bb movb $1, %al ret L_test1_bb6: ## Address Taken LBB1_2: ## %bb6 movb $2, %al ret Note, it is very very strange that BlockAddressSDNode doesn't carry around TargetFlags. Dan, please fix this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85703 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ISelDAGToDAG.cpp | 20 ++++++++++++++------ test/CodeGen/X86/x86-64-jumps.ll | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 test/CodeGen/X86/x86-64-jumps.ll diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp index 4f73f8b812c..122f515249f 100644 --- a/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -71,6 +71,7 @@ namespace { SDValue Segment; GlobalValue *GV; Constant *CP; + BlockAddress *BlockAddr; const char *ES; int JT; unsigned Align; // CP alignment. @@ -78,12 +79,12 @@ namespace { X86ISelAddressMode() : BaseType(RegBase), Scale(1), IndexReg(), Disp(0), - Segment(), GV(0), CP(0), ES(0), JT(-1), Align(0), + Segment(), GV(0), CP(0), BlockAddr(0), ES(0), JT(-1), Align(0), SymbolFlags(X86II::MO_NO_FLAG) { } bool hasSymbolicDisplacement() const { - return GV != 0 || CP != 0 || ES != 0 || JT != -1; + return GV != 0 || CP != 0 || ES != 0 || JT != -1 || BlockAddr != 0; } bool hasBaseOrIndexReg() const { @@ -241,6 +242,9 @@ namespace { Disp = CurDAG->getTargetExternalSymbol(AM.ES, MVT::i32, AM.SymbolFlags); else if (AM.JT != -1) Disp = CurDAG->getTargetJumpTable(AM.JT, MVT::i32, AM.SymbolFlags); + else if (AM.BlockAddr) + Disp = CurDAG->getBlockAddress(AM.BlockAddr, DebugLoc()/*MVT::i32*/, + true /*AM.SymbolFlags*/); else Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i32); @@ -760,10 +764,12 @@ bool X86DAGToDAGISel::MatchWrapper(SDValue N, X86ISelAddressMode &AM) { } else if (ExternalSymbolSDNode *S = dyn_cast(N0)) { AM.ES = S->getSymbol(); AM.SymbolFlags = S->getTargetFlags(); - } else { - JumpTableSDNode *J = cast(N0); + } else if (JumpTableSDNode *J = dyn_cast(N0)) { AM.JT = J->getIndex(); AM.SymbolFlags = J->getTargetFlags(); + } else { + AM.BlockAddr = cast(N0)->getBlockAddress(); + //AM.SymbolFlags = cast(N0)->getTargetFlags(); } if (N.getOpcode() == X86ISD::WrapperRIP) @@ -789,10 +795,12 @@ bool X86DAGToDAGISel::MatchWrapper(SDValue N, X86ISelAddressMode &AM) { } else if (ExternalSymbolSDNode *S = dyn_cast(N0)) { AM.ES = S->getSymbol(); AM.SymbolFlags = S->getTargetFlags(); - } else { - JumpTableSDNode *J = cast(N0); + } else if (JumpTableSDNode *J = dyn_cast(N0)) { AM.JT = J->getIndex(); AM.SymbolFlags = J->getTargetFlags(); + } else { + AM.BlockAddr = cast(N0)->getBlockAddress(); + //AM.SymbolFlags = cast(N0)->getTargetFlags(); } return false; } diff --git a/test/CodeGen/X86/x86-64-jumps.ll b/test/CodeGen/X86/x86-64-jumps.ll new file mode 100644 index 00000000000..5ed6a23ef87 --- /dev/null +++ b/test/CodeGen/X86/x86-64-jumps.ll @@ -0,0 +1,16 @@ +; RUN: llc < %s +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" +target triple = "x86_64-apple-darwin10.0" + +define i8 @test1() nounwind ssp { +entry: + %0 = select i1 undef, i8* blockaddress(@test1, %bb), i8* blockaddress(@test1, %bb6) ; [#uses=1] + indirectbr i8* %0, [label %bb, label %bb6] + +bb: ; preds = %entry + ret i8 1 + +bb6: ; preds = %entry + ret i8 2 +} +