OSDN Git Service

GlobalISel: relax type constraints on G_ICMP to allow pointers.
authorTim Northover <tnorthover@apple.com>
Thu, 15 Sep 2016 10:40:38 +0000 (10:40 +0000)
committerTim Northover <tnorthover@apple.com>
Thu, 15 Sep 2016 10:40:38 +0000 (10:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281600 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
lib/Target/AArch64/AArch64MachineLegalizer.cpp
test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
test/CodeGen/AArch64/GlobalISel/legalize-cmp.mir

index 3c9a7c2..4795aad 100644 (file)
@@ -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 <N x s1>.
   /// \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.
index 7aa5405..afb8079 100644 (file)
@@ -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() &&
index e2165b5..a5a7ed6 100644 (file)
@@ -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);
index 723dcba..2427657 100644 (file)
@@ -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
index 6c889ea..f8a8c32 100644 (file)
@@ -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)
 ...