[llvm] 4130ccc - ValueTracking: Check context instruction is in a function

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu May 18 06:40:32 PDT 2023


Author: Matt Arsenault
Date: 2023-05-18T14:40:13+01:00
New Revision: 4130ccc8be9567bfd8673b2ab1bdcd4f1463af89

URL: https://github.com/llvm/llvm-project/commit/4130ccc8be9567bfd8673b2ab1bdcd4f1463af89
DIFF: https://github.com/llvm/llvm-project/commit/4130ccc8be9567bfd8673b2ab1bdcd4f1463af89.diff

LOG: ValueTracking: Check context instruction is in a function

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp
    llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index bbd7a2487d43..6a008c273794 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4620,6 +4620,9 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
         if ((Known.KnownFPClasses & fcZero) != fcNone &&
             !Known.isKnownNeverSubnormal()) {
           const Function *Parent = II->getFunction();
+          if (!Parent)
+            break;
+
           DenormalMode Mode = Parent->getDenormalMode(
               II->getType()->getScalarType()->getFltSemantics());
           if (Mode != DenormalMode::getIEEE())

diff  --git a/llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll b/llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll
index 06d08e133953..75732960bdd9 100644
--- a/llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll
+++ b/llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll
@@ -138,3 +138,35 @@ define internal i1 @simplify_fcmp_ord_log_callee(double %a) {
 }
 
 declare double @llvm.log.f64(double)
+
+declare float @llvm.maxnum.f32(float, float) #0
+declare <4 x float> @foo() #1
+
+define void @caller_maxnum() {
+; CHECK-LABEL: define void @caller_maxnum() {
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    [[I1_I:%.*]] = call <4 x float> @foo()
+; CHECK-NEXT:    [[I2_I:%.*]] = extractelement <4 x float> [[I1_I]], i64 0
+; CHECK-NEXT:    [[I3_I:%.*]] = fmul float [[I2_I]], 0.000000e+00
+; CHECK-NEXT:    [[I4_I:%.*]] = call float @llvm.maxnum.f32(float [[I3_I]], float 0.000000e+00)
+; CHECK-NEXT:    [[I5_I:%.*]] = call float @llvm.maxnum.f32(float [[I4_I]], float [[I2_I]])
+; CHECK-NEXT:    ret void
+;
+bb:
+  call void @callee_maxnum()
+  ret void
+}
+
+define internal void @callee_maxnum() {
+bb:
+  %i1 = call <4 x float> @foo()
+  %i2 = extractelement <4 x float> %i1, i64 0
+  %i3 = fmul float %i2, 0.000000e+00
+  %i4 = call float @llvm.maxnum.f32(float %i3, float 0.000000e+00)
+  %i5 = call float @llvm.maxnum.f32(float %i4, float %i2)
+  %i6 = fcmp olt float %i5, 0.000000e+00
+  ret void
+}
+
+attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }


        


More information about the llvm-commits mailing list