Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tools/clang/lib/CodeGen/CGHLSLMSFinishCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,15 @@ Value *TryEvalIntrinsic(CallInst *CI, IntrinsicOp intriOp,
};
return EvalTernaryIntrinsic(CI, clampF, clampD, clampI);
} break;
case IntrinsicOp::IOP_fmod: {
auto fmodF = [](float a, float b) -> float {
return a - b * std::truncf(a / b);
};
auto fmodD = [](double a, double b) -> double {
return a - b * std::trunc(a / b);
};
return EvalBinaryIntrinsic(CI, fmodF, fmodD);
} break;
default:
return nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %dxc -T lib_6_x -fcgl %s -E main | %FileCheck %s

// Ensure fmod is constant propagated during codegen
// CHECK: call void {{.*}}results{{.*}}(float 2.500000e+00, float -2.500000e+00, float 2.500000e+00, float -2.500000e+00)
// CHECK: call void {{.*}}results{{.*}}(float 2.500000e+00, float -2.500000e+00, float 2.500000e+00, float -2.500000e+00)

void results(float a, float b, float c, float d);

void main() {
results(
fmod(5.5, 3.0),
fmod(-5.5, 3.0),
fmod(5.5, -3.0),
fmod(-5.5, -3.0));
results(
fmod(5.5f, 3.0f),
fmod(-5.5f, 3.0f),
fmod(5.5f, -3.0f),
fmod(-5.5f, -3.0f));
}