From 4cf0a482bca734dd6cc3d976727feaaf458f2ff4 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Thu, 15 Sep 2016 10:40:38 +0000 Subject: [PATCH] GlobalISel: relax type constraints on G_ICMP to allow pointers. llvm-svn: 281600 --- .../llvm/CodeGen/GlobalISel/MachineIRBuilder.h | 4 ++-- llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp | 4 +--- llvm/lib/Target/AArch64/AArch64MachineLegalizer.cpp | 1 + .../CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll | 12 ++++++++++++ .../test/CodeGen/AArch64/GlobalISel/legalize-cmp.mir | 5 +++++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h index 3c9a7c2a9384..4795aadad7a6 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h @@ -437,8 +437,8 @@ public: /// \pre \p Res must be a generic virtual register with scalar or /// vector type. Typically this starts as s1 or . /// \pre \p Op0 and Op1 must be generic virtual registers with the - /// same number of elements as \p Res (or scalar, if \p Res is - /// scalar). + /// same number of elements as \p Res. If \p Res is a scalar, + /// \p Op0 must be either a scalar or pointer. /// \pre \p Pred must be an integer predicate. /// /// \return a MachineInstrBuilder for the newly created instruction. diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp index 7aa5405ef20b..afb80798b17b 100644 --- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp @@ -321,11 +321,9 @@ MachineInstrBuilder MachineIRBuilder::buildICmp(CmpInst::Predicate Pred, unsigned Res, unsigned Op0, unsigned Op1) { #ifndef NDEBUG - assert((MRI->getType(Op0).isScalar() || MRI->getType(Op0).isVector()) && - "invalid operand type"); assert(MRI->getType(Op0) == MRI->getType(Op0) && "type mismatch"); assert(CmpInst::isIntPredicate(Pred) && "invalid predicate"); - if (MRI->getType(Op0).isScalar()) + if (MRI->getType(Op0).isScalar() || MRI->getType(Op0).isPointer()) assert(MRI->getType(Res).isScalar() && "type mismatch"); else assert(MRI->getType(Res).isVector() && diff --git a/llvm/lib/Target/AArch64/AArch64MachineLegalizer.cpp b/llvm/lib/Target/AArch64/AArch64MachineLegalizer.cpp index e2165b58df51..a5a7ed60ba1f 100644 --- a/llvm/lib/Target/AArch64/AArch64MachineLegalizer.cpp +++ b/llvm/lib/Target/AArch64/AArch64MachineLegalizer.cpp @@ -95,6 +95,7 @@ AArch64MachineLegalizer::AArch64MachineLegalizer() { setAction({G_ICMP, s1}, Legal); setAction({G_ICMP, 1, s32}, Legal); setAction({G_ICMP, 1, s64}, Legal); + setAction({G_ICMP, 1, p0}, Legal); for (auto Ty : {s1, s8, s16}) { setAction({G_ICMP, 1, Ty}, WidenScalar); diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll index 723dcba9b489..24276570581f 100644 --- a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll +++ b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll @@ -542,6 +542,18 @@ define void @int_comparison(i32 %a, i32 %b, i1* %addr) { ret void } +; CHECK-LABEL: name: ptr_comparison +; CHECK: [[LHS:%[0-9]+]](p0) = COPY %x0 +; CHECK: [[RHS:%[0-9]+]](p0) = COPY %x1 +; CHECK: [[ADDR:%[0-9]+]](p0) = COPY %x2 +; CHECK: [[TST:%[0-9]+]](s1) = G_ICMP intpred(eq), [[LHS]](p0), [[RHS]] +; CHECK: G_STORE [[TST]](s1), [[ADDR]](p0) +define void @ptr_comparison(i8* %a, i8* %b, i1* %addr) { + %res = icmp eq i8* %a, %b + store i1 %res, i1* %addr + ret void +} + ; CHECK-LABEL: name: test_fadd ; CHECK: [[ARG1:%[0-9]+]](s32) = COPY %s0 ; CHECK-NEXT: [[ARG2:%[0-9]+]](s32) = COPY %s1 diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-cmp.mir b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-cmp.mir index 6c889ea2cb5b..f8a8c3284dea 100644 --- a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-cmp.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-cmp.mir @@ -21,6 +21,8 @@ registers: - { id: 6, class: _ } - { id: 7, class: _ } - { id: 8, class: _ } + - { id: 9, class: _ } + - { id: 10, class: _ } body: | bb.0.entry: liveins: %x0, %x1, %x2, %x3 @@ -37,4 +39,7 @@ body: | ; CHECK: [[RHS32:%[0-9]+]](s32) = G_ZEXT %3 ; CHECK: %8(s1) = G_ICMP intpred(ult), [[LHS32]](s32), [[RHS32]] %8(s1) = G_ICMP intpred(ult), %2, %3 + + %9(p0) = G_INTTOPTR %0(s64) + %10(s1) = G_ICMP intpred(eq), %9(p0), %9(p0) ... -- GitLab