[llvm] 3b718de - [AggressiveInstCombine] add tests for sqrt with known positive operand; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 27 08:36:20 PDT 2022


Author: Sanjay Patel
Date: 2022-07-27T11:36:12-04:00
New Revision: 3b718de2d3ffa6d392e9f05d7121a2400e82c8c7

URL: https://github.com/llvm/llvm-project/commit/3b718de2d3ffa6d392e9f05d7121a2400e82c8c7
DIFF: https://github.com/llvm/llvm-project/commit/3b718de2d3ffa6d392e9f05d7121a2400e82c8c7.diff

LOG: [AggressiveInstCombine] add tests for sqrt with known positive operand; NFC

Added: 
    

Modified: 
    llvm/test/Transforms/AggressiveInstCombine/X86/sqrt.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/AggressiveInstCombine/X86/sqrt.ll b/llvm/test/Transforms/AggressiveInstCombine/X86/sqrt.ll
index 75dfe0b5898e2..42d7f5870ce4c 100644
--- a/llvm/test/Transforms/AggressiveInstCombine/X86/sqrt.ll
+++ b/llvm/test/Transforms/AggressiveInstCombine/X86/sqrt.ll
@@ -4,6 +4,7 @@
 declare float @sqrtf(float)
 declare double @sqrt(double)
 declare fp128 @sqrtl(fp128)
+declare float @llvm.fabs.f32(float)
 
 ; "nnan" implies no setting of errno and the target can lower this to an
 ; instruction, so transform to an intrinsic.
@@ -51,3 +52,25 @@ define float @sqrt_call_nnan_f32_nobuiltin(float %x) {
   %sqrt = call nnan float @sqrtf(float %x) nobuiltin
   ret float %sqrt
 }
+
+define float @sqrt_call_f32_squared(float %x) {
+; CHECK-LABEL: @sqrt_call_f32_squared(
+; CHECK-NEXT:    [[X2:%.*]] = fmul float [[X:%.*]], [[X]]
+; CHECK-NEXT:    [[SQRT:%.*]] = call float @sqrtf(float [[X2]])
+; CHECK-NEXT:    ret float [[SQRT]]
+;
+  %x2 = fmul float %x, %x
+  %sqrt = call float @sqrtf(float %x2)
+  ret float %sqrt
+}
+
+define float @sqrt_call_f32_fabs(float %x) {
+; CHECK-LABEL: @sqrt_call_f32_fabs(
+; CHECK-NEXT:    [[A:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT:    [[SQRT:%.*]] = call float @sqrtf(float [[A]])
+; CHECK-NEXT:    ret float [[SQRT]]
+;
+  %a = call float @llvm.fabs.f32(float %x)
+  %sqrt = call float @sqrtf(float %a)
+  ret float %sqrt
+}


        


More information about the llvm-commits mailing list