diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-05-04 00:22:23 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-05-04 00:22:23 +0000 |
commit | 2c5aeabeddd0495dcb4b39134f3ab1e89e0d66e5 (patch) | |
tree | 32dfa93b1a184b7d810950164595315380d7099b | |
parent | 6cf4325cb85495487c9be68e4b89933e69164d80 (diff) | |
download | bcm5719-llvm-2c5aeabeddd0495dcb4b39134f3ab1e89e0d66e5.tar.gz bcm5719-llvm-2c5aeabeddd0495dcb4b39134f3ab1e89e0d66e5.zip |
[X86] Lower zext i1 arguments
i1 is now a legal type for X86 with AVX512.
There were some paths in X86FastISel which were not quite ready to see
an i1 value: they were not quite sure how to deal with sign/zero extends
for call arguments.
DTRT by extending to i8 for zeroext and bailing out of FastISel for
signext.
This fixes PR27591.
llvm-svn: 268470
-rw-r--r-- | llvm/lib/Target/X86/X86FastISel.cpp | 15 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/pr27591.ll | 42 |
2 files changed, 57 insertions, 0 deletions
diff --git a/llvm/lib/Target/X86/X86FastISel.cpp b/llvm/lib/Target/X86/X86FastISel.cpp index 6eab3f1d6af..d3894525996 100644 --- a/llvm/lib/Target/X86/X86FastISel.cpp +++ b/llvm/lib/Target/X86/X86FastISel.cpp @@ -3019,6 +3019,10 @@ bool X86FastISel::fastLowerCall(CallLoweringInfo &CLI) { case CCValAssign::SExt: { assert(VA.getLocVT().isInteger() && !VA.getLocVT().isVector() && "Unexpected extend"); + + if (ArgVT.SimpleTy == MVT::i1) + return false; + bool Emitted = X86FastEmitExtend(ISD::SIGN_EXTEND, VA.getLocVT(), ArgReg, ArgVT, ArgReg); assert(Emitted && "Failed to emit a sext!"); (void)Emitted; @@ -3028,6 +3032,17 @@ bool X86FastISel::fastLowerCall(CallLoweringInfo &CLI) { case CCValAssign::ZExt: { assert(VA.getLocVT().isInteger() && !VA.getLocVT().isVector() && "Unexpected extend"); + + // Handle zero-extension from i1 to i8, which is common. + if (ArgVT.SimpleTy == MVT::i1) { + // Set the high bits to zero. + ArgReg = fastEmitZExtFromI1(MVT::i8, ArgReg, /*TODO: Kill=*/false); + ArgVT = MVT::i8; + + if (ArgReg == 0) + return false; + } + bool Emitted = X86FastEmitExtend(ISD::ZERO_EXTEND, VA.getLocVT(), ArgReg, ArgVT, ArgReg); assert(Emitted && "Failed to emit a zext!"); (void)Emitted; diff --git a/llvm/test/CodeGen/X86/pr27591.ll b/llvm/test/CodeGen/X86/pr27591.ll new file mode 100644 index 00000000000..bbafe5960d9 --- /dev/null +++ b/llvm/test/CodeGen/X86/pr27591.ll @@ -0,0 +1,42 @@ +; RUN: llc -o - -O0 < %s | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @test1(i32 %x) #0 { +entry: + %tobool = icmp ne i32 %x, 0 + call void @callee1(i1 zeroext %tobool) + ret void +} + +; CHECK-LABEL: test1: +; CHECK: cmpl $0, %edi +; CHECK-NEXT: setne %al +; CHECK-NEXT: andb $1, %al +; CHECK-NEXT: movzbl %al, %edi +; CHECK-NEXT: callq callee1 + +define void @test2(i32 %x) #0 { +entry: + %tobool = icmp ne i32 %x, 0 + call void @callee2(i1 signext %tobool) + ret void +} + +; CHECK-LABEL: test2: +; CHECK: cmpl $0, %edi +; CHECK-NEXT: setne %al +; CHECK-NEXT: kmovb %eax, %k0 +; CHECK-NEXT: kmovw %k0, %edi +; CHECK-NEXT: andl $1, %edi +; CHECK-NEXT: movb %dil, %al +; CHECK-NEXT: xorl %edi, %edi +; CHECK-NEXT: testb %al, %al +; CHECK-NEXT: movl $-1, %ecx +; CHECK-NEXT: cmovnel %ecx, %edi +; CHECK-NEXT: callq callee2 + +declare void @callee1(i1 zeroext) +declare void @callee2(i1 signext) + +attributes #0 = { nounwind "target-cpu"="skylake-avx512" } |