[llvm] [KnownFPClass] Refine known classes for `atan2(y, x)` when `x` is negative (PR #214629)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 20 21:30:46 PDT 2026
================
@@ -1980,6 +1980,27 @@ TEST_F(ComputeKnownFPClassTest, PowiInfSecond) {
expectKnownFPClass(fcAllFlags, std::nullopt, A7);
}
+TEST_F(ComputeKnownFPClassTest, Atan2DemandXSign) {
+ parseAssembly("declare float @llvm.atan2.f32(float, float)\n"
+ "declare float @llvm.fabs.f32(float)\n"
+ "define float @test(float %y, float %x) #0 {\n"
+ " %abs = call float @llvm.fabs.f32(float %x)\n"
+ " %sum = fadd float %abs, 1.0\n"
+ " %negative = fneg float %sum\n"
+ " %A = call float @llvm.atan2.f32(float %y, float %negative)\n"
+ " ret float %A\n"
+ "}\n"
+ "attributes #0 = { \"denormal-fp-math\"=\"ieee,ieee\" }\n");
+ // atan2(y, -(|x| + 1.0))
+ // Note that -(|x| + 1.0) is never positive, zero, or subnormal.
+ // atan2(y, negative_x) is never zero or subnormal. But we need to know that
+ // x is never positive or a negative subnormal to make this deduction. Which
+ // requires us to pass more than just InterestedClasses, which is the purpose
+ // of this test.
+ KnownFPClass Known = computeKnownFPClass(A, M->getDataLayout(), fcPosZero);
+ EXPECT_EQ(fcNan | fcNormal, Known.KnownFPClasses);
+}
+
----------------
ZERICO2005 wrote:
I was able to come up with this test to justify the existence of this code:
```c++
if ((InterestedClasses & (fcZero | fcSubnormal)) != fcNone)
InterestedX |= fcPositive | fcNegSubnormal;
```
https://github.com/llvm/llvm-project/pull/214629
More information about the llvm-commits
mailing list