[llvm] [InstCombine] Treat `asin`, `asinh`, `atan`, `atan2` and `cbrt` as odd-functions (PR #227336)
Eric Ross via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 29 12:01:09 PDT 2026
================
@@ -20,6 +25,73 @@ define double @test_erf(double %x) {
ret double %neg_res
}
+; Check odd parity: -asin(-x) == asin(x)
+define double @test_asin(double %x) {
+; CHECK-LABEL: define double @test_asin(
+; CHECK-SAME: double [[X:%.*]]) {
+; CHECK-NEXT: [[NEG_RES:%.*]] = tail call reassoc double @asin(double [[X]])
+; CHECK-NEXT: ret double [[NEG_RES]]
+;
+ %neg_x = fneg double %x
+ %res = tail call reassoc double @asin(double %neg_x)
+ %neg_res = fneg double %res
+ ret double %neg_res
+}
+
+; Check odd parity: -asinh(-x) == asinh(x)
+define double @test_asinh(double %x) {
+; CHECK-LABEL: define double @test_asinh(
+; CHECK-SAME: double [[X:%.*]]) {
+; CHECK-NEXT: [[NEG_RES:%.*]] = tail call reassoc double @asinh(double [[X]])
+; CHECK-NEXT: ret double [[NEG_RES]]
+;
+ %neg_x = fneg double %x
+ %res = tail call reassoc double @asinh(double %neg_x)
+ %neg_res = fneg double %res
+ ret double %neg_res
+}
+
+; Check odd parity: -atan(-x) == atan(x)
+define double @test_atan(double %x) {
+; CHECK-LABEL: define double @test_atan(
+; CHECK-SAME: double [[X:%.*]]) {
+; CHECK-NEXT: [[NEG_RES:%.*]] = tail call reassoc double @atan(double [[X]])
+; CHECK-NEXT: ret double [[NEG_RES]]
+;
+ %neg_x = fneg double %x
+ %res = tail call reassoc double @atan(double %neg_x)
+ %neg_res = fneg double %res
+ ret double %neg_res
+}
+
+; Check odd parity: -atan2(-x) == atan2(x)
+define double @test_atan2(double %x) {
+; CHECK-LABEL: define double @test_atan2(
+; CHECK-SAME: double [[X:%.*]]) {
+; CHECK-NEXT: [[NEG_X:%.*]] = fneg double [[X]]
+; CHECK-NEXT: [[RES:%.*]] = tail call reassoc double @atan2(double [[NEG_X]])
+; CHECK-NEXT: [[NEG_RES:%.*]] = fneg double [[RES]]
+; CHECK-NEXT: ret double [[NEG_RES]]
+;
+ %neg_x = fneg double %x
+ %res = tail call reassoc double @atan2(double %neg_x)
----------------
ZERICO2005 wrote:
> I know atan2 should be declared like this, but I have no idea why I got this error and its message seems not to match my code.
This is likely because `optimizeSymmetricCall` is only capable of handling single argument functions.
You can skip implementing `atan2` (but keep the tests for `atan2`), and implement it later in a follow up PR.
https://github.com/llvm/llvm-project/pull/227336
More information about the llvm-commits
mailing list