Skip to content

Commit

Permalink
Better alias handling for layout struct
Browse files Browse the repository at this point in the history
For layout struct, checking uniform/non-uniform is enough for aliasing
them.
  • Loading branch information
jgu222 authored and igcbot committed Jul 2, 2023
1 parent b186fe7 commit 32847ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
11 changes: 9 additions & 2 deletions IGC/Compiler/CISACodeGen/DeSSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ See LICENSE.TXT for details.
//===----------------------------------------------------------------------===//

#include "Compiler/CISACodeGen/DeSSA.hpp"
#include "Compiler/CISACodeGen/MemOpt.h" // isLayoutStructType()
#include "Compiler/CISACodeGen/ShaderCodeGen.hpp"
#include "Compiler/CISACodeGen/PatternMatchPass.hpp"
#include "Compiler/MetaDataApi/MetaDataApi.h"
Expand Down Expand Up @@ -1328,17 +1329,23 @@ void DeSSA::getAllValuesInCongruentClass(

void DeSSA::coalesceAliasInsertValue(InsertValueInst* theIVI)
{
StructType* StTy = dyn_cast<StructType>(theIVI->getType());
bool isLayoutStTy = (StTy != nullptr && isLayoutStructType(StTy));

// Find a chain of insertvalue, and return the last one.
auto getInsValChain = [this](InsertValueInst* aIVI,
auto getInsValChain = [=](InsertValueInst* aIVI,
SmallVector<Value*, 8>& IVIs)
{
InsertValueInst* Inst = aIVI;
const bool isUniform = WIA->isUniform(Inst);
WIAnalysis::WIDependancy Dep = WIA->whichDepend(Inst);
while (Inst && Inst->hasOneUse())
{
IVIs.push_back(Inst);
Inst = dyn_cast<InsertValueInst>(Inst->user_back());
if (Inst && Dep != WIA->whichDepend(Inst)) {
if (Inst &&
((isLayoutStTy && isUniform != WIA->isUniform(Inst)) ||
(!isLayoutStTy && Dep != WIA->whichDepend(Inst)))) {
// Don't group values with differnt dependency.
Inst = nullptr;
}
Expand Down
26 changes: 13 additions & 13 deletions IGC/Compiler/CISACodeGen/MemOpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ namespace IGC {
}

// If struct type is created by LdStCombine() for layout, return true.
bool isLayoutStructType(const StructType* StTy);
bool isLayoutStructType(const llvm::StructType* StTy);
// If struct type is created by LdStCombine() in AOS layout, return true.
// note: if a struct type is a layout struct, but not in AOS layout,
// it must be in SOA layout.
bool isLayoutStructTypeAOS(const StructType* StTy);
bool isLayoutStructTypeSOA(const StructType* StTy);
bool isLayoutStructTypeAOS(const llvm::StructType* StTy);
bool isLayoutStructTypeSOA(const llvm::StructType* StTy);

// bitcastToUI64:
// return C as ui64. C must fit into 64bits.
uint64_t bitcastToUI64(Constant* C, const DataLayout* DL);
uint64_t bitcastToUI64(llvm::Constant* C, const llvm::DataLayout* DL);

// getStructMemberOffsetType_1:
// Given a struct type 'StTy' and its 'Indices', return the type and
// the byte offset of the member referred to by {StTy, Indices}.
// This member must be at level 1.
// The function checks to make sure 'Indices' has size of 1.
void getStructMemberByteOffsetAndType_1(const DataLayout* DL,
StructType* StTy, const ArrayRef<unsigned>& Indices,
Type*& Ty, uint32_t& ByteOffset);
void getStructMemberByteOffsetAndType_1(const llvm::DataLayout* DL,
llvm::StructType* StTy, const llvm::ArrayRef<unsigned>& Indices,
llvm::Type*& Ty, uint32_t& ByteOffset);

// getStructMemberOffsetType_2:
// Given a struct type 'StTy' and its 'Indices', return the types and
Expand All @@ -64,10 +64,10 @@ namespace IGC {
// {Ty1, ByteOffset1} is for level 2 if it is at level 2 (Ty1 must not
// be nullptr).
// The function checks to maek sure 'Indices' has size of 2 at most.
void getStructMemberOffsetAndType_2(const DataLayout* DL,
StructType* StTy, const ArrayRef<unsigned>& Indices,
Type*& Ty0, uint32_t& ByteOffset0,
Type*& Ty1, uint32_t& ByteOffset1);
void getStructMemberOffsetAndType_2(const llvm::DataLayout* DL,
llvm::StructType* StTy, const llvm::ArrayRef<unsigned>& Indices,
llvm::Type*& Ty0, uint32_t& ByteOffset0,
llvm::Type*& Ty1, uint32_t& ByteOffset1);

// getAllDefinedMembers
// Given a value 'V' of struct type, return all the indices of members
Expand All @@ -81,8 +81,8 @@ namespace IGC {
// %10 = insertvalue %9, i32 %5, 2
//
// The value %9 will return {0, 1}, and %10 will return {0, 1, 2}.
void getAllDefinedMembers(const Value* IVI,
std::list<ArrayRef<unsigned>>& fieldsTBC);
void getAllDefinedMembers(const llvm::Value* IVI,
std::list<llvm::ArrayRef<unsigned>>& fieldsTBC);
}

#endif // _CISA_MEMOPT_H_

0 comments on commit 32847ec

Please sign in to comment.