From c3d1504d6316c11164e5edb9415e6fb43bb705f3 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 1 Sep 2022 08:32:06 -0400 Subject: [PATCH] [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 --- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 1 + llvm/test/Transforms/InstCombine/fcmp.ll | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 4a0ba31..834bb60 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 198a715..960e1b7 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 +} -- 2.7.4