]> granicus.if.org Git - llvm/commitdiff
[GlobalISel] Relax vector G_SELECT assertion.
authorAhmed Bougacha <ahmed.bougacha@gmail.com>
Tue, 7 Mar 2017 20:53:03 +0000 (20:53 +0000)
committerAhmed Bougacha <ahmed.bougacha@gmail.com>
Tue, 7 Mar 2017 20:53:03 +0000 (20:53 +0000)
For vector operands, the `select` instruction supports both vector and
non-vector conditions.  The MIR builder had an overly restrictive
assertion, that only accepted vector conditions for vector selects
(in effect implementing ISD::VSELECT).

Make it possible to express the full range of G_SELECTs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297207 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll

index ce84bb94dcf585106a0971460ec74317255378f5..9745340a05af1eed86caf7b113a7d649cb366354 100644 (file)
@@ -568,9 +568,10 @@ MachineInstrBuilder MachineIRBuilder::buildSelect(unsigned Res, unsigned Tst,
   if (ResTy.isScalar() || ResTy.isPointer())
     assert(MRI->getType(Tst).isScalar() && "type mismatch");
   else
-    assert(MRI->getType(Tst).isVector() &&
-           MRI->getType(Tst).getNumElements() ==
-               MRI->getType(Op0).getNumElements() &&
+    assert((MRI->getType(Tst).isScalar() ||
+            (MRI->getType(Tst).isVector() &&
+             MRI->getType(Tst).getNumElements() ==
+                 MRI->getType(Op0).getNumElements())) &&
            "type mismatch");
 #endif
 
index 17ed0169c98d00c8e6574f8875008f4a1f7e238f..1bbda24f444602887dd3aa1071fb4994ecf95a4f 100644 (file)
@@ -945,6 +945,17 @@ define i8* @test_select_ptr(i1 %tst, i8* %lhs, i8* %rhs) {
   ret i8* %res
 }
 
+; CHECK-LABEL: name: test_select_vec
+; CHECK: [[TST:%[0-9]+]](s1) = COPY %w0
+; CHECK: [[LHS:%[0-9]+]](<4 x s32>) = COPY %q0
+; CHECK: [[RHS:%[0-9]+]](<4 x s32>) = COPY %q1
+; CHECK: [[RES:%[0-9]+]](<4 x s32>) = G_SELECT [[TST]](s1), [[LHS]], [[RHS]]
+; CHECK: %q0 = COPY [[RES]]
+define <4 x i32> @test_select_vec(i1 %tst, <4 x i32> %lhs, <4 x i32> %rhs) {
+  %res = select i1 %tst, <4 x i32> %lhs, <4 x i32> %rhs
+  ret <4 x i32> %res
+}
+
 ; CHECK-LABEL: name: test_vselect_vec
 ; CHECK: [[TST32:%[0-9]+]](<4 x s32>) = COPY %q0
 ; CHECK: [[LHS:%[0-9]+]](<4 x s32>) = COPY %q1