OSDN Git Service

[ARM] GlobalISel: Support G_SELECT for pointers
authorDiana Picus <diana.picus@linaro.org>
Tue, 27 Jun 2017 10:29:50 +0000 (10:29 +0000)
committerDiana Picus <diana.picus@linaro.org>
Tue, 27 Jun 2017 10:29:50 +0000 (10:29 +0000)
All we need to do is mark it as legal, otherwise it's just like s32.

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

lib/Target/ARM/ARMLegalizerInfo.cpp
test/CodeGen/ARM/GlobalISel/arm-instruction-select.mir
test/CodeGen/ARM/GlobalISel/arm-isel.ll
test/CodeGen/ARM/GlobalISel/arm-legalizer.mir

index 7ec7bab..0b6738c 100644 (file)
@@ -85,6 +85,7 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) {
   setAction({G_GEP, 1, s32}, Legal);
 
   setAction({G_SELECT, s32}, Legal);
+  setAction({G_SELECT, p0}, Legal);
   setAction({G_SELECT, 1, s1}, Legal);
 
   setAction({G_CONSTANT, s32}, Legal);
index ab04b39..6a1da0d 100644 (file)
@@ -42,7 +42,8 @@
   define void @test_constant_imm() { ret void }
   define void @test_constant_cimm() { ret void }
 
-  define void @test_select() { ret void }
+  define void @test_select_s32() { ret void }
+  define void @test_select_ptr() { ret void }
 
   define void @test_soft_fp_double() #0 { ret void }
 
@@ -1102,8 +1103,8 @@ body:             |
     BX_RET 14, _, implicit %r0
 ...
 ---
-name:            test_select
-# CHECK-LABEL: name: test_select
+name:            test_select_s32
+# CHECK-LABEL: name: test_select_s32
 legalized:       true
 regBankSelected: true
 selected:        false
@@ -1137,6 +1138,41 @@ body:             |
     ; CHECK: BX_RET 14, _, implicit %r0
 ...
 ---
+name:            test_select_ptr
+# CHECK-LABEL: name: test_select_ptr
+legalized:       true
+regBankSelected: true
+selected:        false
+# CHECK: selected: true
+registers:
+  - { id: 0, class: gprb }
+  - { id: 1, class: gprb }
+  - { id: 2, class: gprb }
+  - { id: 3, class: gprb }
+body:             |
+  bb.0:
+    liveins: %r0, %r1, %r2
+
+    %0(p0) = COPY %r0
+    ; CHECK: [[VREGX:%[0-9]+]] = COPY %r0
+
+    %1(p0) = COPY %r1
+    ; CHECK: [[VREGY:%[0-9]+]] = COPY %r1
+
+    %2(s1) = COPY %r2
+    ; CHECK: [[VREGC:%[0-9]+]] = COPY %r2
+
+    %3(p0) = G_SELECT %2(s1),  %0, %1
+    ; CHECK: CMPri [[VREGC]], 0, 14, _, implicit-def %cpsr
+    ; CHECK: [[RES:%[0-9]+]] = MOVCCr [[VREGX]], [[VREGY]], 0, %cpsr
+
+    %r0 = COPY %3(p0)
+    ; CHECK: %r0 = COPY [[RES]]
+
+    BX_RET 14, _, implicit %r0
+    ; CHECK: BX_RET 14, _, implicit %r0
+...
+---
 name:            test_soft_fp_double
 # CHECK-LABEL: name: test_soft_fp_double
 legalized:       true
index 01b4bbd..4c498ff 100644 (file)
@@ -410,3 +410,13 @@ entry:
   %r = select i1 %cond, i32 %a, i32 %b
   ret i32 %r
 }
+
+define arm_aapcscc i32* @test_select_ptr(i32* %a, i32* %b, i1 %cond) {
+; CHECK-LABEL: test_select_ptr
+; CHECK: cmp r2, #0
+; CHECK: moveq r0, r1
+; CHECK: bx lr
+entry:
+  %r = select i1 %cond, i32* %a, i32* %b
+  ret i32* %r
+}
index 4cf83c3..bf75972 100644 (file)
@@ -40,6 +40,7 @@
   define void @test_icmp_s32() { ret void }
 
   define void @test_select_s32() { ret void }
+  define void @test_select_ptr() { ret void }
 
   define void @test_fadd_s32() #0 { ret void }
   define void @test_fadd_s64() #0 { ret void }
@@ -803,6 +804,32 @@ body:             |
     BX_RET 14, _, implicit %r0
 ...
 ---
+name:            test_select_ptr
+# CHECK-LABEL: name: test_select_ptr
+legalized:       false
+# CHECK: legalized: true
+regBankSelected: false
+selected:        false
+tracksRegLiveness: true
+registers:
+  - { id: 0, class: _ }
+  - { id: 1, class: _ }
+  - { id: 2, class: _ }
+  - { id: 3, class: _ }
+body:             |
+  bb.0:
+    liveins: %r0, %r1, %r2
+
+    %0(p0) = COPY %r0
+    %1(p0) = COPY %r1
+    %2(s1) = COPY %r2
+    %3(p0) = G_SELECT %2(s1), %0, %1
+    ; G_SELECT with p0 is legal, so we should find it unchanged in the output
+    ; CHECK: {{%[0-9]+}}(p0) = G_SELECT {{%[0-9]+}}(s1), {{%[0-9]+}}, {{%[0-9]+}}
+    %r0 = COPY %3(p0)
+    BX_RET 14, _, implicit %r0
+...
+---
 name:            test_fadd_s32
 # CHECK-LABEL: name: test_fadd_s32
 legalized:       false