microsoft / microsoft/DirectXShaderCompiler

pow of literal 0.0f not optimized away in some cases

Open
#6,557 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug correctness
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
When using float pow(float x, float y) intrinsic, supplying 0.0f for x should return 0.0f. This fails in some cases.

Steps to Reproduce

// dxc -T ps_6_0 -E main

#define TEST 0
// TEST = 0,3 - fails to optimize away log+mul+exp
// TEST = 1,2,4 - optimizes to return 0.0f

float main() : SV_Target0
{
#if TEST == 0
    float x = 0.0f;
    return pow(x, 2.2f);
#elif TEST == 1
    const float x = 0.0f;
    return pow(x, 2.2f);
#elif TEST == 2
    float x = 0.0f;
    return pow(x, 2.0f);
#elif TEST == 3
    return pow(saturate(0.0f), 2.2f);
#else
    return pow(0.0f, 2.2f);
#endif
}

See repro in Compiler Explorer.

Actual Behavior
When TEST = 0,3 - fails to optimize away log+mul+exp.
When TEST = 1,2,4 - optimizes to return 0.0f (expected behavior for all cases).

Environment

  • DXC version: 1.8.2403 and latest main
  • Host Operating System: any

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided dxc command and HLSL example, comparing TEST values 0 through 4 and the generated output. Trace the pow intrinsic optimization or lowering path first; done means TEST=0 and TEST=3 also optimize to return 0.0f without the log, multiply, and exp sequence.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.