From 07ffcb10074a9b62e3c65c544f6df9252a333f0d Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Wed, 5 Nov 2014 19:27:21 +0000 Subject: [PATCH 1/1] [x86 fast-isel] Materialize allocas with the correct-sized lea for ILP32 Summary: X86FastISel::fastMaterializeAlloca was incorrectly conditioning its opcode selection on subtarget bitness rather than pointer size. Differential Revision: http://reviews.llvm.org/D6136 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221386 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86FastISel.cpp | 2 +- test/CodeGen/X86/fast-isel-x32.ll | 14 ++++++++++++++ test/CodeGen/X86/fast-isel-x86-64.ll | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/X86/fast-isel-x32.ll diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp index 4c9fef5c3b2..95cb71857cd 100644 --- a/lib/Target/X86/X86FastISel.cpp +++ b/lib/Target/X86/X86FastISel.cpp @@ -3271,7 +3271,7 @@ unsigned X86FastISel::fastMaterializeAlloca(const AllocaInst *C) { X86AddressMode AM; if (!X86SelectAddress(C, AM)) return 0; - unsigned Opc = Subtarget->is64Bit() ? X86::LEA64r : X86::LEA32r; + unsigned Opc = TLI.getPointerTy() == MVT::i32 ? X86::LEA32r : X86::LEA64r; const TargetRegisterClass* RC = TLI.getRegClassFor(TLI.getPointerTy()); unsigned ResultReg = createResultReg(RC); addFullAddress(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, diff --git a/test/CodeGen/X86/fast-isel-x32.ll b/test/CodeGen/X86/fast-isel-x32.ll new file mode 100644 index 00000000000..d02b936fe92 --- /dev/null +++ b/test/CodeGen/X86/fast-isel-x32.ll @@ -0,0 +1,14 @@ +; RUN: llc < %s -mtriple=x86_64-linux-gnux32 -fast-isel -fast-isel-abort -regalloc=fast | FileCheck %s +; RUN: llc < %s -mtriple=x86_64-nacl -fast-isel -fast-isel-abort -regalloc=fast | FileCheck %s + +; Test that alloca addresses are materialized with the right size instruction. + +declare void @bar(i32* %arg) + +; CHECK-LABEL: @foo +define void @foo() { + %a = alloca i32 +; CHECK: leal {{.*}}, %edi + call void @bar(i32* %a) + ret void +} diff --git a/test/CodeGen/X86/fast-isel-x86-64.ll b/test/CodeGen/X86/fast-isel-x86-64.ll index 33abc385ebd..3747d049424 100644 --- a/test/CodeGen/X86/fast-isel-x86-64.ll +++ b/test/CodeGen/X86/fast-isel-x86-64.ll @@ -302,3 +302,13 @@ define void @test23(i8* noalias sret %result) { } declare i8* @foo23() + +declare void @takesi32ptr(i32* %arg) + +; CHECK-LABEL: allocamaterialize +define void @allocamaterialize() { + %a = alloca i32 +; CHECK: leaq {{.*}}, %rdi + call void @takesi32ptr(i32* %a) + ret void +} -- 2.34.1