Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Remove unneeded unconditional jumps #69041

Merged
merged 22 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/coreclr/jit/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1472,8 +1472,11 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

public:
void instGen(instruction ins);

#if defined(TARGET_XARCH)
void inst_JMP(emitJumpKind jmp, BasicBlock* tgtBlock, bool isRemovableJmpCandidate = false);
Wraith2 marked this conversation as resolved.
Show resolved Hide resolved
#else
void inst_JMP(emitJumpKind jmp, BasicBlock* tgtBlock);
#endif

void inst_SET(emitJumpKind condition, regNumber reg);

Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4301,6 +4301,18 @@ void CodeGen::inst_SETCC(GenCondition condition, var_types type, regNumber dstRe
#endif
}

//------------------------------------------------------------------------
// inst_JMP: Generate a jump instruction.
//
void CodeGen::inst_JMP(emitJumpKind jmp, BasicBlock* tgtBlock)
{
#if !FEATURE_FIXED_OUT_ARGS
Wraith2 marked this conversation as resolved.
Show resolved Hide resolved
assert((tgtBlock->bbTgtStkDepth * sizeof(int) == genStackLevel) || isFramePointerUsed());
#endif // !FEATURE_FIXED_OUT_ARGS

GetEmitter()->emitIns_J(emitter::emitJumpKindToIns(jmp), tgtBlock);
}

//------------------------------------------------------------------------
// genCodeForStoreBlk: Produce code for a GT_STORE_OBJ/GT_STORE_DYN_BLK/GT_STORE_BLK node.
//
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1944,11 +1944,12 @@ void CodeGen::genGenerateMachineCode()
#endif // DEBUG

/* We can now generate the function prolog and epilog */

genGeneratePrologsAndEpilogs();

/* Bind jump distances */
// check to see if any jumps can be removed
GetEmitter()->emitRemoveJumpToNextInst();

/* Bind jump distances */
GetEmitter()->emitJumpDistBind();

#if FEATURE_LOOP_ALIGN
Expand Down
19 changes: 18 additions & 1 deletion src/coreclr/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,24 @@ void CodeGen::genCodeForBBlist()
break;

case BBJ_ALWAYS:
inst_JMP(EJ_jmp, block->bbJumpDest);
inst_JMP(EJ_jmp, block->bbJumpDest
#ifdef TARGET_AMD64
// AMD64 requires an instruction after a call instruction for unwinding
// inside an EH region so if the last instruction generated was a call instruction
// do not allow this jump to be marked for possible later removal.
//
// If a block was selected to place an alignment instruction because it ended
// with a jump, do not remove jumps from such blocks.
,
/* isRemovableJmpCandidate */ !GetEmitter()->emitIsLastInsCall() && !block->hasAlign()
#else
#ifdef TARGET_XARCH
,
/* isRemovableJmpCandidate */ !block->hasAlign()
#endif

#endif
);
FALLTHROUGH;

case BBJ_COND:
Expand Down
24 changes: 24 additions & 0 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,30 @@ void CodeGen::inst_SETCC(GenCondition condition, var_types type, regNumber dstRe
}
}

//------------------------------------------------------------------------
// inst_JMP: Generate a jump instruction.
//
void CodeGen::inst_JMP(emitJumpKind jmp, BasicBlock* tgtBlock, bool isRemovableJmpCandidate)
{
#if !FEATURE_FIXED_OUT_ARGS
// On the x86 we are pushing (and changing the stack level), but on x64 and other archs we have
// a fixed outgoing args area that we store into and we never change the stack level when calling methods.
//
// Thus only on x86 do we need to assert that the stack level at the target block matches the current stack level.
//
CLANG_FORMAT_COMMENT_ANCHOR;

#ifdef UNIX_X86_ABI
// bbTgtStkDepth is a (pure) argument count (stack alignment padding should be excluded).
assert((tgtBlock->bbTgtStkDepth * sizeof(int) == (genStackLevel - curNestedAlignment)) || isFramePointerUsed());
#else
assert((tgtBlock->bbTgtStkDepth * sizeof(int) == genStackLevel) || isFramePointerUsed());
#endif
#endif // !FEATURE_FIXED_OUT_ARGS

GetEmitter()->emitIns_J(emitter::emitJumpKindToIns(jmp), tgtBlock, 0, isRemovableJmpCandidate);
}

//------------------------------------------------------------------------
// genCodeForReturnTrap: Produce code for a GT_RETURNTRAP node.
//
Expand Down
Loading