]> granicus.if.org Git - llvm/commitdiff
GlobalISel: deal with new G_PTR_MASK instruction on AArch64.
authorTim Northover <tnorthover@apple.com>
Tue, 14 Feb 2017 20:56:29 +0000 (20:56 +0000)
committerTim Northover <tnorthover@apple.com>
Tue, 14 Feb 2017 20:56:29 +0000 (20:56 +0000)
It's just an AND-immediate instruction for us, surprisingly simple to select.

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

lib/Target/AArch64/AArch64InstructionSelector.cpp
lib/Target/AArch64/AArch64LegalizerInfo.cpp
test/CodeGen/AArch64/GlobalISel/arm64-instructionselect.mir

index 6bced17d09d79730147eae9da15e52b729bb7704..f83c7f0e6cc0a3b62aaca08a58f22fa7a66c4304 100644 (file)
@@ -816,6 +816,17 @@ bool AArch64InstructionSelector::select(MachineInstr &I) const {
     return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
   }
 
+  case TargetOpcode::G_PTR_MASK: {
+    uint64_t Align = I.getOperand(2).getImm();
+    if (Align >= 64 || Align == 0)
+      return false;
+
+    uint64_t Mask = ~((1ULL << Align) - 1);
+    I.setDesc(TII.get(AArch64::ANDXri));
+    I.getOperand(2).setImm(AArch64_AM::encodeLogicalImmediate(Mask, 64));
+
+    return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
+  }
   case TargetOpcode::G_PTRTOINT:
   case TargetOpcode::G_TRUNC: {
     const LLT DstTy = MRI.getType(I.getOperand(0).getReg());
index c978be9ab10d6e526a9f557febceecbd4da75e81..fc224d22a13e7f2ac6bfb1be4877be5dc2aac7c7 100644 (file)
@@ -52,6 +52,8 @@ AArch64LegalizerInfo::AArch64LegalizerInfo() {
   for (auto Ty : {s1, s8, s16, s32})
     setAction({G_GEP, 1, Ty}, WidenScalar);
 
+  setAction({G_PTR_MASK, p0}, Legal);
+
   for (unsigned BinOp : {G_LSHR, G_ASHR, G_SDIV, G_UDIV}) {
     for (auto Ty : {s32, s64})
       setAction({BinOp, Ty}, Legal);
index c07dd60ee6a1484fd80d11580810764ea16585a3..55329aa5b27facfb09920b74666739f116b16cba 100644 (file)
 
   define i8* @gep(i8* %in) { ret i8* undef }
 
+  define i8* @ptr_mask(i8* %in) { ret i8* undef }
+
   @var_local = global i8 0
   define i8* @global_local() { ret i8* undef }
 
@@ -2043,6 +2045,21 @@ body:             |
     %2(p0) = G_GEP %0, %1(s64)
 ...
 
+---
+# CHECK-LABEL: name: ptr_mask
+name:            ptr_mask
+legalized:       true
+regBankSelected: true
+
+# CHECK:  body:
+# CHECK: %1 = ANDXri %0, 8060
+body:             |
+  bb.0:
+      liveins: %x0
+    %0:gpr(p0) = COPY %x0
+    %1:gpr(p0) = G_PTR_MASK %0, 3
+...
+
 ---
 # Global defined in the same linkage unit so no GOT is needed
 # CHECK-LABEL: name: global_local