aboutsummaryrefslogtreecommitdiff
path: root/source/opt/vector_dce.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/opt/vector_dce.cpp')
-rw-r--r--source/opt/vector_dce.cpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/source/opt/vector_dce.cpp b/source/opt/vector_dce.cpp
index 14a55c1e..28d94a07 100644
--- a/source/opt/vector_dce.cpp
+++ b/source/opt/vector_dce.cpp
@@ -52,7 +52,7 @@ void VectorDCE::FindLiveComponents(Function* function,
// components are live because of arbitrary nesting of structs.
function->ForEachInst(
[&work_list, this, live_components](Instruction* current_inst) {
- if (current_inst->IsOpenCL100DebugInstr()) {
+ if (current_inst->IsCommonDebugInstr()) {
return;
}
if (!HasVectorOrScalarResult(current_inst) ||
@@ -110,7 +110,11 @@ void VectorDCE::MarkExtractUseAsLive(const Instruction* current_inst,
if (current_inst->NumInOperands() < 2) {
new_item.components = live_elements;
} else {
- new_item.components.Set(current_inst->GetSingleWordInOperand(1));
+ uint32_t element_index = current_inst->GetSingleWordInOperand(1);
+ uint32_t item_size = GetVectorComponentCount(operand_inst->type_id());
+ if (element_index < item_size) {
+ new_item.components.Set(element_index);
+ }
}
AddItemToWorkListIfNeeded(new_item, live_components, work_list);
}
@@ -176,10 +180,10 @@ void VectorDCE::MarkVectorShuffleUsesAsLive(
second_operand.instruction =
def_use_mgr->GetDef(current_item.instruction->GetSingleWordInOperand(1));
- analysis::TypeManager* type_mgr = context()->get_type_mgr();
- analysis::Vector* first_type =
- type_mgr->GetType(first_operand.instruction->type_id())->AsVector();
- uint32_t size_of_first_operand = first_type->element_count();
+ uint32_t size_of_first_operand =
+ GetVectorComponentCount(first_operand.instruction->type_id());
+ uint32_t size_of_second_operand =
+ GetVectorComponentCount(second_operand.instruction->type_id());
for (uint32_t in_op = 2; in_op < current_item.instruction->NumInOperands();
++in_op) {
@@ -187,7 +191,7 @@ void VectorDCE::MarkVectorShuffleUsesAsLive(
if (current_item.components.Get(in_op - 2)) {
if (index < size_of_first_operand) {
first_operand.components.Set(index);
- } else {
+ } else if (index - size_of_first_operand < size_of_second_operand) {
second_operand.components.Set(index - size_of_first_operand);
}
}
@@ -202,7 +206,6 @@ void VectorDCE::MarkCompositeContructUsesAsLive(
VectorDCE::LiveComponentMap* live_components,
std::vector<VectorDCE::WorkListItem>* work_list) {
analysis::DefUseManager* def_use_mgr = context()->get_def_use_mgr();
- analysis::TypeManager* type_mgr = context()->get_type_mgr();
uint32_t current_component = 0;
Instruction* current_inst = work_item.instruction;
@@ -223,8 +226,7 @@ void VectorDCE::MarkCompositeContructUsesAsLive(
assert(HasVectorResult(op_inst));
WorkListItem new_work_item;
new_work_item.instruction = op_inst;
- uint32_t op_vector_size =
- type_mgr->GetType(op_inst->type_id())->AsVector()->element_count();
+ uint32_t op_vector_size = GetVectorComponentCount(op_inst->type_id());
for (uint32_t op_vector_idx = 0; op_vector_idx < op_vector_size;
op_vector_idx++, current_component++) {
@@ -297,6 +299,18 @@ bool VectorDCE::HasScalarResult(const Instruction* inst) const {
}
}
+uint32_t VectorDCE::GetVectorComponentCount(uint32_t type_id) {
+ assert(type_id != 0 &&
+ "Trying to get the vector element count, but the type id is 0");
+ analysis::TypeManager* type_mgr = context()->get_type_mgr();
+ const analysis::Type* type = type_mgr->GetType(type_id);
+ const analysis::Vector* vector_type = type->AsVector();
+ assert(
+ vector_type &&
+ "Trying to get the vector element count, but the type is not a vector");
+ return vector_type->element_count();
+}
+
bool VectorDCE::RewriteInstructions(
Function* function, const VectorDCE::LiveComponentMap& live_components) {
bool modified = false;
@@ -394,7 +408,7 @@ void VectorDCE::MarkDebugValueUsesAsDead(
Instruction* composite, std::vector<Instruction*>* dead_dbg_value) {
context()->get_def_use_mgr()->ForEachUser(
composite, [&dead_dbg_value](Instruction* use) {
- if (use->GetOpenCL100DebugOpcode() == OpenCLDebugInfo100DebugValue)
+ if (use->GetCommonDebugOpcode() == CommonDebugInfoDebugValue)
dead_dbg_value->push_back(use);
});
}