From 5fe1a569099272cbe3cec4972c52e5531223b58e Mon Sep 17 00:00:00 2001 From: SwapnilGaikwad Date: Wed, 24 Apr 2024 16:07:10 +0100 Subject: [PATCH] Fix checks to accommodate register wraparounds in multi-reg ops (#101430) Fixes issue #101070 --- src/coreclr/jit/codegen.h | 10 ++++++++++ src/coreclr/jit/hwintrinsiccodegenarm64.cpp | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/codegen.h b/src/coreclr/jit/codegen.h index f5e0dc857a7d4..441db5f6b50d4 100644 --- a/src/coreclr/jit/codegen.h +++ b/src/coreclr/jit/codegen.h @@ -101,6 +101,16 @@ class CodeGen final : public CodeGenInterface } } +#if defined(TARGET_ARM64) + regNumber getNextSIMDRegWithWraparound(regNumber reg) + { + regNumber nextReg = REG_NEXT(reg); + + // Wraparound if necessary, REG_V0 comes next after REG_V31. + return (nextReg > REG_V31) ? REG_V0 : nextReg; + } +#endif // defined(TARGET_ARM64) + static GenTreeIndir indirForm(var_types type, GenTree* base); static GenTreeStoreInd storeIndirForm(var_types type, GenTree* base, GenTree* data); diff --git a/src/coreclr/jit/hwintrinsiccodegenarm64.cpp b/src/coreclr/jit/hwintrinsiccodegenarm64.cpp index 9a3a98e087a27..01914951576bf 100644 --- a/src/coreclr/jit/hwintrinsiccodegenarm64.cpp +++ b/src/coreclr/jit/hwintrinsiccodegenarm64.cpp @@ -833,7 +833,7 @@ void CodeGen::genHWIntrinsic(GenTreeHWIntrinsic* node) GenTree* argNode = use.GetNode(); assert(argReg == argNode->GetRegNum()); - argReg = REG_NEXT(argReg); + argReg = getNextSIMDRegWithWraparound(argReg); } assert((ins == INS_st2 && regCount == 2) || (ins == INS_st3 && regCount == 3) || (ins == INS_st4 && regCount == 4)); @@ -883,7 +883,7 @@ void CodeGen::genHWIntrinsic(GenTreeHWIntrinsic* node) GenTree* argNode = use.GetNode(); assert(argReg == argNode->GetRegNum()); - argReg = REG_NEXT(argReg); + argReg = getNextSIMDRegWithWraparound(argReg); } assert((ins == INS_st1_2regs && regCount == 2) || (ins == INS_st2 && regCount == 2) || (ins == INS_st1_3regs && regCount == 3) || (ins == INS_st3 && regCount == 3) || @@ -1186,7 +1186,7 @@ void CodeGen::genHWIntrinsic(GenTreeHWIntrinsic* node) GenTree* argNode = use.GetNode(); assert(argReg == argNode->GetRegNum()); - argReg = REG_NEXT(argReg); + argReg = getNextSIMDRegWithWraparound(argReg); #endif } } @@ -1241,7 +1241,7 @@ void CodeGen::genHWIntrinsic(GenTreeHWIntrinsic* node) assert(argReg == argNode->GetRegNum()); // and they should not interfere with targetReg assert(targetReg != argReg); - argReg = REG_NEXT(argReg); + argReg = getNextSIMDRegWithWraparound(argReg); #endif } }