AMDGPU/GlobalISel: Fix crash in regbankselect on non-power-of-2 types
authorTom Stellard <tstellar@redhat.com>
Fri, 27 Jul 2018 06:04:40 +0000 (06:04 +0000)
committerTom Stellard <tstellar@redhat.com>
Fri, 27 Jul 2018 06:04:40 +0000 (06:04 +0000)
Reviewers: arsenm

Reviewed By: arsenm

Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, dstuttard, tpr, llvm-commits, t-tye

Differential Revision: https://reviews.llvm.org/D49624

llvm-svn: 338102

llvm/lib/Target/AMDGPU/AMDGPUGenRegisterBankInfo.def
llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect.mir

index ef2dab7..3a58c6c 100644 (file)
@@ -96,7 +96,7 @@ const RegisterBankInfo::ValueMapping *getValueMapping(unsigned BankID,
     break;
   default:
     Idx = BankID == AMDGPU::VGPRRegBankID ? VGPRStartIdx : SGPRStartIdx;
-    Idx += llvm::countTrailingZeros(Size);
+    Idx += Log2_32_Ceil(Size);
     break;
   }
   return &ValMappings[Idx];
index bd95b70..70c5419 100644 (file)
@@ -14,6 +14,7 @@
     %tmp2 = load i32, i32 addrspace(1)* %tmp1
     ret void
   }
+  define void @non_power_of_2() { ret void }
   declare i32 @llvm.amdgcn.workitem.id.x() #0
   attributes #0 = { nounwind readnone }
 ...
@@ -67,3 +68,19 @@ body: |
     %0:_(p1) = COPY $sgpr0_sgpr1
     %1:_(s32) = G_LOAD %0 :: (load 4 from %ir.tmp1)
 ...
+
+---
+name: non_power_of_2
+legalized: true
+
+# CHECK-LABEL: name: non_power_of_2
+# CHECK: [[S448:%[0-9]+]]:sgpr(s448) = G_IMPLICIT_DEF
+# CHECK: sgpr(s32) = G_EXTRACT [[S448]](s448), 0
+
+body: |
+  bb.0:
+    %0:_(s448) = G_IMPLICIT_DEF
+    %1:_(s32) = G_EXTRACT %0:_(s448), 0
+    $sgpr0 = COPY %1:_(s32)
+    SI_RETURN_TO_EPILOG $sgpr0
+...