Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generation is incorrect with impure functions due to optimization pass #3746

Closed
ArielG-NV opened this issue Mar 12, 2024 · 1 comment · Fixed by #3762
Closed

Code generation is incorrect with impure functions due to optimization pass #3746

ArielG-NV opened this issue Mar 12, 2024 · 1 comment · Fixed by #3762
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang kind:bug something doesn't work like it should

Comments

@ArielG-NV
Copy link
Collaborator

ArielG-NV commented Mar 12, 2024

The first call to simplifyIR (after lowerLValueCast in linkAndOptimizeIR) simplifies functions which are impure and have side effects in the body (and not the arguments). It is likely all simplifyIR calls exhibit this behavior.

edit:
This issue is due to incorrect checking in isPureFunctionalCall

example case:

//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -emit-spirv-directly
#version 430
precision highp float;
precision highp int;

//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
buffer MyBlockName2
{
    uint data[1];
} outputBuffer;

layout(local_size_x = 4) in;

void sideEffectInit(int val)
{
    outputBuffer.data[0] = val;
}
void computeMain()
{
    outputBuffer.data[0] = 1000;
    sideEffectInit(4);
    // BUF: 4
}

this compiles computeMain currently into:

void computeMain()
{
    outputBuffer.data[0] = 1000;
}

computeMain should instead compile effectively into:

void computeMain()
{
    outputBuffer.data[0] = 1000;
    sideEffectInit(4);
}
@ArielG-NV ArielG-NV added kind:bug something doesn't work like it should goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang labels Mar 12, 2024
@csyonghe
Copy link
Collaborator

isPureFunctionCall looks for the IRReadNoneDecoration on the callee, which is propagated during propagateFuncProperties.

propagateFuncProperties does check for the body of the function for any side effects.

In this case I suspect the root cause is that the stores into a GLSL storage buffer isn't counted as having global side effect for some reason. Need to debug into propagateFuncPropertiesImpl to see why it decides the function has no side effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang kind:bug something doesn't work like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants