[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 11:57:51 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:

>  define double @atan2_f64(double %a) { 
 ; CHECK-LABEL: atan2_f64 
 ; CHECK: __xl_atan2_finite 
 ; CHECK: blr 
 entry: 
   %call = tail call nnan ninf afn nsz double @atan2(double %a) 
   ret double %call 
 } 

Yeah that test does not look correct.

https://github.com/llvm/llvm-project/pull/227336


More information about the llvm-commits mailing list