Skip to content

SimplifyLibCalls: Skip sincospi optimization for ConstantData #134688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Apr 7, 2025

Avoids looking at the uselist, and it would probably be more
productive to constant fold this.

Copy link
Contributor Author

arsenm commented Apr 7, 2025

@llvmbot
Copy link
Member

llvmbot commented Apr 7, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

Avoids looking at the uselist, and it would probably be more
productive to constant fold this.


Full diff: https://github.com/llvm/llvm-project/pull/134688.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp (+3)
  • (modified) llvm/test/Transforms/InstCombine/sincospi.ll (+8-16)
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 2d0027d976019..4e37c587dc975 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3002,6 +3002,9 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, bool IsSin, IRBuilderBa
     return nullptr;
 
   Value *Arg = CI->getArgOperand(0);
+  if (isa<ConstantData>(Arg))
+    return nullptr;
+
   SmallVector<CallInst *, 1> SinCalls;
   SmallVector<CallInst *, 1> CosCalls;
   SmallVector<CallInst *, 1> SinCosCalls;
diff --git a/llvm/test/Transforms/InstCombine/sincospi.ll b/llvm/test/Transforms/InstCombine/sincospi.ll
index b76ae20171147..14da03dff6f49 100644
--- a/llvm/test/Transforms/InstCombine/sincospi.ll
+++ b/llvm/test/Transforms/InstCombine/sincospi.ll
@@ -90,18 +90,14 @@ define float @test_instbased_f32_other_user(ptr %ptr) {
 
 define float @test_constant_f32() {
 ; CHECK-FLOAT-IN-VEC-LABEL: @test_constant_f32(
-; CHECK-FLOAT-IN-VEC-NEXT:    [[SINCOSPI:%.*]] = call <2 x float> @__sincospif_stret(float 1.000000e+00)
-; CHECK-FLOAT-IN-VEC-NEXT:    [[SINPI:%.*]] = extractelement <2 x float> [[SINCOSPI]], i64 0
-; CHECK-FLOAT-IN-VEC-NEXT:    [[COSPI:%.*]] = extractelement <2 x float> [[SINCOSPI]], i64 1
-; CHECK-FLOAT-IN-VEC-NEXT:    [[COS:%.*]] = call float @__cospif(float 1.000000e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:    [[SINPI:%.*]] = call float @__sinpif(float 1.000000e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:    [[COSPI:%.*]] = call float @__cospif(float 1.000000e+00) #[[ATTR0]]
 ; CHECK-FLOAT-IN-VEC-NEXT:    [[RES:%.*]] = fadd float [[SINPI]], [[COSPI]]
 ; CHECK-FLOAT-IN-VEC-NEXT:    ret float [[RES]]
 ;
 ; CHECK-LABEL: @test_constant_f32(
-; CHECK-NEXT:    [[SINCOSPI:%.*]] = call { float, float } @__sincospif_stret(float 1.000000e+00)
-; CHECK-NEXT:    [[SINPI:%.*]] = extractvalue { float, float } [[SINCOSPI]], 0
-; CHECK-NEXT:    [[COSPI:%.*]] = extractvalue { float, float } [[SINCOSPI]], 1
-; CHECK-NEXT:    [[COS:%.*]] = call float @__cospif(float 1.000000e+00) #[[ATTR0]]
+; CHECK-NEXT:    [[SINPI:%.*]] = call float @__sinpif(float 1.000000e+00) #[[ATTR0]]
+; CHECK-NEXT:    [[COSPI:%.*]] = call float @__cospif(float 1.000000e+00) #[[ATTR0]]
 ; CHECK-NEXT:    [[RES:%.*]] = fadd float [[SINPI]], [[COSPI]]
 ; CHECK-NEXT:    ret float [[RES]]
 ;
@@ -172,18 +168,14 @@ define double @test_instbased_f64() {
 
 define double @test_constant_f64() {
 ; CHECK-FLOAT-IN-VEC-LABEL: @test_constant_f64(
-; CHECK-FLOAT-IN-VEC-NEXT:    [[SINCOSPI:%.*]] = call { double, double } @__sincospi_stret(double 1.000000e+00)
-; CHECK-FLOAT-IN-VEC-NEXT:    [[SINPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 0
-; CHECK-FLOAT-IN-VEC-NEXT:    [[COSPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 1
-; CHECK-FLOAT-IN-VEC-NEXT:    [[COS:%.*]] = call double @__cospi(double 1.000000e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:    [[SINPI:%.*]] = call double @__sinpi(double 1.000000e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:    [[COSPI:%.*]] = call double @__cospi(double 1.000000e+00) #[[ATTR0]]
 ; CHECK-FLOAT-IN-VEC-NEXT:    [[RES:%.*]] = fadd double [[SINPI]], [[COSPI]]
 ; CHECK-FLOAT-IN-VEC-NEXT:    ret double [[RES]]
 ;
 ; CHECK-LABEL: @test_constant_f64(
-; CHECK-NEXT:    [[SINCOSPI:%.*]] = call { double, double } @__sincospi_stret(double 1.000000e+00)
-; CHECK-NEXT:    [[SINPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 0
-; CHECK-NEXT:    [[COSPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 1
-; CHECK-NEXT:    [[COS:%.*]] = call double @__cospi(double 1.000000e+00) #[[ATTR0]]
+; CHECK-NEXT:    [[SINPI:%.*]] = call double @__sinpi(double 1.000000e+00) #[[ATTR0]]
+; CHECK-NEXT:    [[COSPI:%.*]] = call double @__cospi(double 1.000000e+00) #[[ATTR0]]
 ; CHECK-NEXT:    [[RES:%.*]] = fadd double [[SINPI]], [[COSPI]]
 ; CHECK-NEXT:    ret double [[RES]]
 ;

@arsenm arsenm removed request for gottesmm and ahatanak April 7, 2025 16:57
@arsenm arsenm marked this pull request as ready for review April 7, 2025 16:57
@llvmbot llvmbot added the llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes label Apr 7, 2025
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arsenm arsenm force-pushed the users/arsenm/objc-arc-contract-use-stripPointerCastsAndAliases branch from 981f435 to 6614a6b Compare April 8, 2025 00:24
@arsenm arsenm force-pushed the users/arsenm/instcombine-skip-sincospi-optimization-constantdata branch 2 times, most recently from c0e8aed to e0e5a05 Compare April 12, 2025 09:25
@arsenm arsenm force-pushed the users/arsenm/objc-arc-contract-use-stripPointerCastsAndAliases branch from 6614a6b to 238597d Compare April 12, 2025 09:25
Avoids looking at the uselist, and it would probably be more
productive to constant fold this.
@arsenm arsenm force-pushed the users/arsenm/instcombine-skip-sincospi-optimization-constantdata branch from e0e5a05 to a59013c Compare April 13, 2025 10:16
@arsenm arsenm force-pushed the users/arsenm/objc-arc-contract-use-stripPointerCastsAndAliases branch from 238597d to cfd2525 Compare April 13, 2025 10:16
arsenm added a commit that referenced this pull request Apr 13, 2025
Avoids looking at the uselist, and it would probably be more
productive to constant fold this.
@arsenm
Copy link
Contributor Author

arsenm commented Apr 13, 2025

a24ef4b

@arsenm arsenm closed this Apr 13, 2025
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…34688)

Avoids looking at the uselist, and it would probably be more
productive to constant fold this.
@arsenm arsenm deleted the users/arsenm/instcombine-skip-sincospi-optimization-constantdata branch April 25, 2025 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants