[llvm] [InstCombine] Fix foldIntrinsicIsFPClass to use subset check for fold… (PR #196716)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 9 05:20:25 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Vishal Kumar Patwa (cs25mtech12013-commits)

<details>
<summary>Changes</summary>

…-to-true

Use Known.isKnownAlways(Mask) instead of equality when folding is.fpclass to true. The old check missed cases where the known classes are a proper subset of the test mask. Fixes #<!-- -->189949

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


2 Files Affected:

- (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/is_fpclass.ll (+9) 


``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index b4e2ebea4d196..9ccdc1b117cd5 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1180,7 +1180,7 @@ Instruction *InstCombinerImpl::foldIntrinsicIsFPClass(IntrinsicInst &II) {
   // If none of the tests which can return false are possible, fold to true.
   // fp_class (nnan x), ~(qnan|snan) -> true
   // fp_class (ninf x), ~(ninf|pinf) -> true
-  if (Mask == Known.KnownFPClasses)
+  if (Known.isKnownAlways(Mask))
     return replaceInstUsesWith(II, ConstantInt::get(II.getType(), true));
 
   return nullptr;
diff --git a/llvm/test/Transforms/InstCombine/is_fpclass.ll b/llvm/test/Transforms/InstCombine/is_fpclass.ll
index a4f7a43adf1e5..c0406682f1b68 100644
--- a/llvm/test/Transforms/InstCombine/is_fpclass.ll
+++ b/llvm/test/Transforms/InstCombine/is_fpclass.ll
@@ -3954,6 +3954,15 @@ entry:
   ret i1 %test
 }
 
+; Fold to true when known classes are a subset of the test mask.
+define i1 @test_pnorm_subset_normal_fold(float nofpclass(nan inf zero sub nnorm) %x) {
+; CHECK-LABEL: @test_pnorm_subset_normal_fold(
+; CHECK-NEXT:    ret i1 true
+;
+  %r = call i1 @llvm.is.fpclass.f32(float %x, i32 264)
+  ret i1 %r
+}
+
 declare i1 @llvm.is.fpclass.f32(float, i32 immarg)
 declare i1 @llvm.is.fpclass.f64(double, i32 immarg)
 declare <2 x i1> @llvm.is.fpclass.v2f32(<2 x float>, i32 immarg)

``````````

</details>


https://github.com/llvm/llvm-project/pull/196716


More information about the llvm-commits mailing list