[llvm] 987eb8e - [InstCombine] propagate sign argument through nested copysigns

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 30 08:08:56 PST 2019


Author: Sanjay Patel
Date: 2019-12-30T11:06:02-05:00
New Revision: 987eb8e26ccf73180b3b53b8a38d87e3e6489326

URL: https://github.com/llvm/llvm-project/commit/987eb8e26ccf73180b3b53b8a38d87e3e6489326
DIFF: https://github.com/llvm/llvm-project/commit/987eb8e26ccf73180b3b53b8a38d87e3e6489326.diff

LOG: [InstCombine] propagate sign argument through nested copysigns

This is another optimization suggested in PR44153:
https://bugs.llvm.org/show_bug.cgi?id=44153

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/test/Transforms/InstCombine/copysign.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index d1c078fb74ed..e4a73c659b69 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2302,6 +2302,16 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
                                                  II->getArgOperand(0), II);
       return replaceInstUsesWith(*II, Builder.CreateFNegFMF(Fabs, II));
     }
+
+    // Propagate sign argument through nested calls:
+    // copysign X, (copysign ?, SignArg) --> copysign X, SignArg
+    Value *SignArg;
+    if (match(II->getArgOperand(1),
+              m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(SignArg)))) {
+      II->setArgOperand(1, SignArg);
+      return II;
+    }
+
     break;
   }
   case Intrinsic::fabs: {

diff  --git a/llvm/test/Transforms/InstCombine/copysign.ll b/llvm/test/Transforms/InstCombine/copysign.ll
index 79c13380d4c7..a77da83a40d9 100644
--- a/llvm/test/Transforms/InstCombine/copysign.ll
+++ b/llvm/test/Transforms/InstCombine/copysign.ll
@@ -68,8 +68,7 @@ define <3 x double> @known_positive_sign_arg_vec(<3 x double> %x, <3 x i32> %y)
 
 define float @copysign_sign_arg(float %x, float %y, float %z) {
 ; CHECK-LABEL: @copysign_sign_arg(
-; CHECK-NEXT:    [[S:%.*]] = call reassoc float @llvm.copysign.f32(float [[Y:%.*]], float [[Z:%.*]])
-; CHECK-NEXT:    [[R:%.*]] = call ninf float @llvm.copysign.f32(float [[X:%.*]], float [[S]])
+; CHECK-NEXT:    [[R:%.*]] = call ninf float @llvm.copysign.f32(float [[X:%.*]], float [[Z:%.*]])
 ; CHECK-NEXT:    ret float [[R]]
 ;
   %s = call reassoc float @llvm.copysign.f32(float %y, float %z)


        


More information about the llvm-commits mailing list