Skip to content

Commit 6171f7e

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Fix some register size issues
Summary: Fix an assortment of register size issues: 1) Add/sub are overflow safe 2) Sign extending needs to always use a 32-bit register (we'll select the correct operation based upon the instruction) 3) Large op constants need to have matching data types Reviewed By: alexmalyshev Differential Revision: D93808171 fbshipit-source-id: 3c1a0c6fc4f52f22572b97b5bca274dded09a386
1 parent ad505a8 commit 6171f7e

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

cinderx/Jit/codegen/autogen.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ void translateCall(Environ* env, const Instruction* instr) {
19611961
if (output->isVecD()) {
19621962
as->mov(AT::getVecD(output), a64::d0);
19631963
} else {
1964-
auto out_reg = AT::getGp(output);
1964+
auto out_reg = AT::getGpOutput(output);
19651965
// Match the source register width to the destination register width.
19661966
// aarch64 mov requires both operands to be the same size.
19671967
if (out_reg.isGpW()) {
@@ -2159,7 +2159,7 @@ void translateMovExtOp(
21592159
int input_size = input->sizeInBits();
21602160

21612161
if (input->isReg()) {
2162-
auto input_reg = AT::getGp(input);
2162+
auto input_reg = AT::getGp(DataType::k32bit, input->getPhyRegister().loc);
21632163

21642164
switch (input_size) {
21652165
case 8:
@@ -2169,7 +2169,7 @@ void translateMovExtOp(
21692169
emit_ext16(as, output, input_reg);
21702170
break;
21712171
case 32:
2172-
as->mov(a64::w(output.id()), a64::w(input_reg.id()));
2172+
as->mov(a64::w(output.id()), input_reg);
21732173
break;
21742174
default:
21752175
JIT_ABORT("Unsupported input size for {}: {}", opname, input_size);
@@ -2269,16 +2269,16 @@ void translateAddSubOp(
22692269
JIT_CHECK(output->isReg(), "Expected output to be a register");
22702270
JIT_CHECK(opnd0->isReg(), "Expected opnd0 to be a register");
22712271

2272-
auto output_reg = AT::getGp(output);
2273-
auto opnd0_reg = AT::getGp(opnd0);
2272+
auto output_reg = AT::getGpOutput(output);
2273+
auto opnd0_reg = AT::getGpOverflowSafe(opnd0);
22742274

22752275
if (opnd1->isImm()) {
22762276
uint64_t constant = opnd1->getConstant();
22772277
JIT_CHECK(arm::Utils::isAddSubImm(constant), "Out of range");
22782278

22792279
emit(as, output_reg, opnd0_reg, constant);
22802280
} else if (opnd1->isReg()) {
2281-
emit(as, output_reg, opnd0_reg, AT::getGp(opnd1));
2281+
emit(as, output_reg, opnd0_reg, AT::getGpOverflowSafe(opnd1));
22822282
} else if (opnd1->isStack()) {
22832283
auto loc = opnd1->getStackSlot().loc;
22842284
auto ptr = arch::ptr_resolve(as, arch::fp, loc, arch::reg_scratch_0);

cinderx/Jit/codegen/autogen.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ class AutoTranslator {
129129
return getGpOutput(op, op->getPhyRegister().loc);
130130
}
131131

132+
static arch::Gp getGpOverflowSafe(const jit::lir::OperandBase* op) {
133+
return getGpOutput(op, op->getPhyRegister().loc);
134+
}
135+
132136
private:
133137
AutoTranslator() {
134138
initTable();

cinderx/Jit/lir/postgen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ RewriteResult rewriteBinaryOpLargeConstant(instr_iter_t instr_iter) {
150150
auto move = block->allocateInstrBefore(
151151
instr_iter,
152152
Instruction::kMove,
153-
OutVReg{},
153+
OutVReg{in1->dataType()},
154154
Imm{constant, in1->dataType()});
155155

156156
// If the first operand is smaller in size than the second operand, replace

0 commit comments

Comments
 (0)