Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ichttt committed May 28, 2023
1 parent 5cd3a2d commit 8287925
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/hotspot/cpu/x86/peephole_x86_64.cpp
Expand Up @@ -142,21 +142,24 @@ bool Peephole::lea_coalesce_imm(Block* block, int block_index, PhaseCFG* cfg_, P
return lea_coalesce_helper(block, block_index, cfg_, ra_, new_root, inst0_rule, true);
}

// This function removes the TEST instruction when it detected shapes likes AND r1, r2; TEST r1, r1
bool Peephole::test_may_remove(Block* block, int block_index, PhaseCFG* cfg_, PhaseRegAlloc* ra_,
MachNode* (*new_root)(), uint inst0_rule, uint inst1_rule) {
MachNode* inst0 = block->get_node(block_index)->as_Mach();
assert(inst0->rule() == inst0_rule, "sanity");

Node* inst1 = inst0->in(1);
// Only remove test if the block order is inst1 -> MachProjNode (cause AND specifies KILL cr) -> inst0
if (block_index < 2 || !block->get_node(block_index - 1)->is_MachProj() || block->get_node(block_index - 2) != inst1) {
// So inst1 must be at index - 2
if (block_index < 2 || block->get_node(block_index - 2) != inst1) {
return false;
}
if (inst1 != nullptr) {
if (inst1->is_Mach()) {
MachNode* maybeAndNode = inst1->as_Mach();
MachNode* maybeAndNode = inst1->isa_Mach();
if (maybeAndNode != nullptr) {
if (maybeAndNode->rule() == inst1_rule) {
// Remove the original test node and replace it with the pseudo test node. The and node already sets ZF
assert(block->get_node(block_index - 1)->is_MachProj(), "Expected a MachProj node here!");
// Remove the original test node and replace it with the pseudo test node. The AND node already sets ZF
MachNode* root = new_root();
// Assign register for the newly allocated node
ra_->set_oop(root, ra_->is_oop(inst0));
Expand Down

0 comments on commit 8287925

Please sign in to comment.