[llvm] c3d1504 - [InstCombine] fix crash on type mismatch with fcmp fold

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 1 05:59:44 PDT 2022


Author: Sanjay Patel
Date: 2022-09-01T08:57:55-04:00
New Revision: c3d1504d6316c11164e5edb9415e6fb43bb705f3

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

LOG: [InstCombine] fix crash on type mismatch with fcmp fold

The existing predicate doesn't work for a single-element
vector, so make sure we are not crossing scalar/vector types.

Test (was crashing) based on the post-commit example for:
482777123427

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/test/Transforms/InstCombine/fcmp.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 4a0ba31087df..834bb60a2ce6 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -6892,6 +6892,7 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
   // fcmp oeq/une (bitcast X), 0.0 --> (and X, SignMaskC) ==/!= 0
   if (match(Op1, m_PosZeroFP()) &&
       match(Op0, m_OneUse(m_BitCast(m_Value(X)))) &&
+      X->getType()->isVectorTy() == OpType->isVectorTy() &&
       X->getType()->getScalarSizeInBits() == OpType->getScalarSizeInBits()) {
     ICmpInst::Predicate IntPred = ICmpInst::BAD_ICMP_PREDICATE;
     if (Pred == FCmpInst::FCMP_OEQ)

diff  --git a/llvm/test/Transforms/InstCombine/fcmp.ll b/llvm/test/Transforms/InstCombine/fcmp.ll
index 198a71504a56..960e1b7712a6 100644
--- a/llvm/test/Transforms/InstCombine/fcmp.ll
+++ b/llvm/test/Transforms/InstCombine/fcmp.ll
@@ -1275,3 +1275,16 @@ define i1 @bitcast_gt0(i32 %x) {
   %r = fcmp ogt float %f, 0.0
   ret i1 %r
 }
+
+; negative test - this could be transformed, but requires a new bitcast
+
+define <1 x i1> @bitcast_1vec_eq0(i32 %x) {
+; CHECK-LABEL: @bitcast_1vec_eq0(
+; CHECK-NEXT:    [[F:%.*]] = bitcast i32 [[X:%.*]] to <1 x float>
+; CHECK-NEXT:    [[CMP:%.*]] = fcmp oeq <1 x float> [[F]], zeroinitializer
+; CHECK-NEXT:    ret <1 x i1> [[CMP]]
+;
+  %f = bitcast i32 %x to <1 x float>
+  %cmp = fcmp oeq <1 x float> %f, zeroinitializer
+  ret <1 x i1> %cmp
+}


        


More information about the llvm-commits mailing list