[PATCH] R600/SI: Fix off by 1 error in used register count

Tom Stellard tom at stellard.net
Thu Sep 11 14:20:59 PDT 2014


On Thu, Sep 11, 2014 at 08:46:32PM +0000, Matt Arsenault wrote:
> The register numbers start at 0, so if only 1 register was used, this was reported as 0.
> 
> http://reviews.llvm.org/D5312
> 
> Files:
>   lib/Target/R600/AMDGPUAsmPrinter.cpp
>   test/CodeGen/R600/no_vgpr_used.ll

> Index: lib/Target/R600/AMDGPUAsmPrinter.cpp
> ===================================================================
> --- lib/Target/R600/AMDGPUAsmPrinter.cpp
> +++ lib/Target/R600/AMDGPUAsmPrinter.cpp
> @@ -314,7 +314,7 @@
>            llvm_unreachable("Unknown register class");
>          }
>          unsigned hwReg = RI->getEncodingValue(reg) & 0xff;
> -        unsigned maxUsed = hwReg + width - 1;
> +        unsigned maxUsed = hwReg + width;

I thin it would be better to do this instead:

  ProgInfo.NumVGPR = MaxVGPR + 1;
  ProgInfo.NumSGPR = MaxSGPR + 1;

-Tom

>          if (isSGPR) {
>            MaxSGPR = maxUsed > MaxSGPR ? maxUsed : MaxSGPR;
>          } else {
> Index: test/CodeGen/R600/no_vgpr_used.ll
> ===================================================================
> --- /dev/null
> +++ test/CodeGen/R600/no_vgpr_used.ll
> @@ -0,0 +1,8 @@
> +; RUN: llc -march=r600 -mcpu=SI -verify-machineinstrs < %s | FileCheck -check-prefix=SI %s
> +
> +; SI-LABEL: @no_vgpr_used
> +; SI: NumVgprs: 1
> +define void @no_vgpr_used(i32 addrspace(1)* %out, i32 %x) nounwind {
> +  store i32 %x, i32 addrspace(1)* %out, align 4
> +  ret void
> +}

> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list