From f50f2f3d3268b016c9940adabcadc1e8378303b5 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 6 Dec 2016 18:38:34 +0000 Subject: [PATCH] GlobalISel: allow G_SELECT instructions for pointers. llvm-svn: 288835 --- .../llvm/CodeGen/GlobalISel/MachineIRBuilder.h | 2 +- llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp | 9 +++++---- .../CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll | 11 +++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h index c98aa68e4796..97839d472718 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h @@ -488,7 +488,7 @@ public: /// \pre setBasicBlock or setMI must have been called. /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers /// with the same type. - /// \pre \p Tst must be a generic virtual register with scalar or + /// \pre \p Tst must be a generic virtual register with scalar, pointer or /// vector type. If vector then it must have the same number of /// elements as the other parameters. /// diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp index 69ce50339829..d46dd9f6b8f6 100644 --- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp @@ -392,11 +392,12 @@ MachineInstrBuilder MachineIRBuilder::buildFCmp(CmpInst::Predicate Pred, MachineInstrBuilder MachineIRBuilder::buildSelect(unsigned Res, unsigned Tst, unsigned Op0, unsigned Op1) { #ifndef NDEBUG - assert((MRI->getType(Res).isScalar() || MRI->getType(Res).isVector()) && + LLT ResTy = MRI->getType(Res); + assert((ResTy.isScalar() || ResTy.isVector() || ResTy.isPointer()) && "invalid operand type"); - assert(MRI->getType(Res) == MRI->getType(Op0) && - MRI->getType(Res) == MRI->getType(Op1) && "type mismatch"); - if (MRI->getType(Res).isScalar()) + assert(ResTy == MRI->getType(Op0) && ResTy == MRI->getType(Op1) && + "type mismatch"); + if (ResTy.isScalar() || ResTy.isPointer()) assert(MRI->getType(Tst).isScalar() && "type mismatch"); else assert(MRI->getType(Tst).isVector() && diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll index f9ef78470ebb..ad353bfa9ab3 100644 --- a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll +++ b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll @@ -761,6 +761,17 @@ define i32 @test_select(i1 %tst, i32 %lhs, i32 %rhs) { ret i32 %res } +; CHECK-LABEL: name: test_select_ptr +; CHECK: [[TST:%[0-9]+]](s1) = COPY %w0 +; CHECK: [[LHS:%[0-9]+]](p0) = COPY %x1 +; CHECK: [[RHS:%[0-9]+]](p0) = COPY %x2 +; CHECK: [[RES:%[0-9]+]](p0) = G_SELECT [[TST]](s1), [[LHS]], [[RHS]] +; CHECK: %x0 = COPY [[RES]] +define i8* @test_select_ptr(i1 %tst, i8* %lhs, i8* %rhs) { + %res = select i1 %tst, i8* %lhs, i8* %rhs + ret i8* %res +} + ; CHECK-LABEL: name: test_fptosi ; CHECK: [[FPADDR:%[0-9]+]](p0) = COPY %x0 ; CHECK: [[FP:%[0-9]+]](s32) = G_LOAD [[FPADDR]](p0)