Skip structurize when only 1 ret. (#3754)

This commit is contained in:
Xiang Li 2021-05-06 22:39:31 -07:00 коммит произвёл GitHub
Родитель 254af3a55a
Коммит 2298848552
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 23 добавлений и 1 удалений

Просмотреть файл

@ -3149,7 +3149,7 @@ ScopeInfo::ScopeInfo(Function *F) : maxRetLevel(0), bAllReturnsInIf(true) {
// When all returns is inside if which is not nested, the flow is still
// structurized even there're more than one return.
bool ScopeInfo::CanSkipStructurize() {
return bAllReturnsInIf && maxRetLevel < 2;
return (bAllReturnsInIf && maxRetLevel < 2) || rets.size() < 2;
}
void ScopeInfo::AddScope(Scope::ScopeKind k, BasicBlock *endScopeBB) {

Просмотреть файл

@ -0,0 +1,22 @@
// RUN: %dxc -Emain -opt-enable structurize-returns -Tps_6_0 %s | FileCheck %s
// Make sure not crash.
// CHECK:call %dx.types.ResRet.i32 @dx.op.bufferLoad
struct ST
{
uint a;
};
StructuredBuffer<ST> buf;
uint main(uint i:I) : SV_Target {
for(;;)
{
if(i<buf[i].a)
i++;
else
return buf[i].a;
}
}