[llvm] 7322d35 - [ValueTracking] Fix computeKnownFPClass with canonicalize

Piotr Sobczak via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 05:51:15 PDT 2023


Author: Piotr Sobczak
Date: 2023-05-15T14:50:35+02:00
New Revision: 7322d35476c34aa92720088554fb627154a99a6e

URL: https://github.com/llvm/llvm-project/commit/7322d35476c34aa92720088554fb627154a99a6e
DIFF: https://github.com/llvm/llvm-project/commit/7322d35476c34aa92720088554fb627154a99a6e.diff

LOG: [ValueTracking] Fix computeKnownFPClass with canonicalize

Update code that assumes llvm.canonicalize only handles scalars,
by adding a call to getScalarType().
This is fine, as the intrinsic is trivially vectorizable.

Introduced in D147870, and uncovered by D148065.

Differential Revision: https://reviews.llvm.org/D150556

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp
    llvm/test/Transforms/InstCombine/canonicalize.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index a4b3a927b6c8b..ca02a9671c5e7 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4801,7 +4801,8 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
 
         // If the parent function flushes denormals, the canonical output cannot
         // be a denormal.
-        const fltSemantics &FPType = II->getType()->getFltSemantics();
+        const fltSemantics &FPType =
+            II->getType()->getScalarType()->getFltSemantics();
         DenormalMode DenormMode = II->getFunction()->getDenormalMode(FPType);
         if (DenormMode.inputsAreZero() || DenormMode.outputsAreZero())
           Known.knownNot(fcSubnormal);

diff  --git a/llvm/test/Transforms/InstCombine/canonicalize.ll b/llvm/test/Transforms/InstCombine/canonicalize.ll
index b0f01f797a6ee..0905898e2f44b 100644
--- a/llvm/test/Transforms/InstCombine/canonicalize.ll
+++ b/llvm/test/Transforms/InstCombine/canonicalize.ll
@@ -457,5 +457,20 @@ define i1 @canonicalize_uno_arg_f32(float %x) {
   ret i1 %cmp
 }
 
+; --------------------------------------------------------------------
+; Others
+; --------------------------------------------------------------------
+
+; Regression test checking that the vector version of llvm.canonicalize works.
+define <2 x i1> @vec_canonicalize_with_fpclass(<2 x float> %x) {
+; CHECK-LABEL: @vec_canonicalize_with_fpclass(
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
+;
+  %canon = call <2 x float> @llvm.canonicalize.v2f32(<2 x float> %x)
+  %fpclass = call <2 x i1> @llvm.is.fpclass.v2f32(<2 x float> %canon, i32 1)
+  ret <2 x i1> %fpclass
+}
+
 declare float @llvm.canonicalize.f32(float)
 declare <2 x float> @llvm.canonicalize.v2f32(<2 x float>)
+declare <2 x i1> @llvm.is.fpclass.v2f32(<2 x float>, i32 immarg)


        


More information about the llvm-commits mailing list