Fixed lifetime marker causing unroll to fail (#4830)
Fixed a bug where enabling lifetime markers causes unroll to fail. Running instcombine before loop unroll may cause unroll to fail, because instcombine may rewrite expressions in a way that makes ScalarEvolutions unable to evaluate. This change replaces the instcombine with simplify-inst, which serves the same purpose as the instcombine, but leaves the expression easy for ScalarEvolutions to evaluate. Also moved the original test for instcombine to a new folder with the new test, since instcombine pass is no longer being tested for that test. The problematic expression rewrite was as follows: ``` limit = (non_const_int_value % 2) ? 1 : 2; ``` Instcombine rewrites it to ``` limit = 2 - (non_const_int_value & 1); ``` Which stumped ScalarEvolutions.
This commit is contained in:
Родитель
7d9567cf80
Коммит
5b2201db00
|
@ -270,7 +270,7 @@ static void addHLSLPasses(bool HLSLHighLevel, unsigned OptLevel, bool OnlyWarnOn
|
||||||
// without interfering with HLSL-specific lowering.
|
// without interfering with HLSL-specific lowering.
|
||||||
if (EnableLifetimeMarkers) {
|
if (EnableLifetimeMarkers) {
|
||||||
MPM.add(createSROAPass());
|
MPM.add(createSROAPass());
|
||||||
MPM.add(createInstructionCombiningPass());
|
MPM.add(createSimplifyInstPass());
|
||||||
MPM.add(createJumpThreadingPass());
|
MPM.add(createJumpThreadingPass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
// RUN: %dxc -T ps_6_6 %s -enable-lifetime-markers /HV 2021 | FileCheck %s
|
||||||
|
// RUN: %dxc -T ps_6_6 %s /Od -enable-lifetime-markers /HV 2021 | FileCheck %s
|
||||||
|
|
||||||
|
// CHECK: @main
|
||||||
|
|
||||||
|
//
|
||||||
|
// Regression check for loop unrolling failure. Running instcombine when
|
||||||
|
// lifetime markers are enabled rewrote the IR in a way that ScalarEvolution
|
||||||
|
// could no longer figure out an upper bound. The expression:
|
||||||
|
//
|
||||||
|
// limit = (l % 2) ? 1 : 2;
|
||||||
|
//
|
||||||
|
// Got rewritten to
|
||||||
|
//
|
||||||
|
// limit = 2 - (l & 1);
|
||||||
|
//
|
||||||
|
// This fix for this was switching from running instcombine to running
|
||||||
|
// simplifyinst, which is less aggressive in its rewriting.
|
||||||
|
//
|
||||||
|
|
||||||
|
cbuffer cb : register(b0) {
|
||||||
|
float foo[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
[RootSignature("CBV(b0)")]
|
||||||
|
float main(uint l : L) : SV_Target {
|
||||||
|
uint limit = (l % 2) ? 1 : 2;
|
||||||
|
float ret = 0;
|
||||||
|
[unroll]
|
||||||
|
for (uint i = 0; i < limit; i++) {
|
||||||
|
ret += foo[i];
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче