Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4863,8 +4863,9 @@ Value *B = getOrCreateVectorValue(Cmp->getOperand(1), Part); Value *C = nullptr; if (FCmp) { + IRBuilder<>::FastMathFlagGuard FMFG(Builder); + Builder.setFastMathFlags(Cmp->getFastMathFlags()); C = Builder.CreateFCmp(Cmp->getPredicate(), A, B); - cast(C)->copyFastMathFlags(Cmp); } else { C = Builder.CreateICmp(Cmp->getPredicate(), A, B); } Index: test/Transforms/LoopVectorize/fcmp-vectorize.ll =================================================================== --- /dev/null +++ test/Transforms/LoopVectorize/fcmp-vectorize.ll @@ -0,0 +1,29 @@ +; RUN: opt -loop-vectorize -S %s | FileCheck %s + +; REQUIRES: asserts +; Avoid crashing while trying to vectorize fcmp that can be folded to vector of +; i1 true. +define void @test1() { +; CHECK-LABEL: test1( +; CHECK-LABEL: vector.body: +; CHECK-NEXT: %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ] +; CHECK-NEXT: %broadcast.splatinsert = insertelement <4 x i32> undef, i32 %index, i32 0 +; CHECK: %induction = add <4 x i32> %broadcast.splat, +; CHECK: %index.next = add i32 %index, 4 + +; CHECK-LABEL: loop: +; CHECK-NEXT: %iv = phi i32 [ %bc.resume.val, %scalar.ph ], [ %ivnext, %loop ] +; CHECK-NEXT: %fcmp = fcmp uno float 0.000000e+00, 0.000000e+00 +entry: + br label %loop + +loop: ; preds = %loop, %entry + %iv = phi i32 [ 0, %entry ], [ %ivnext, %loop ] + %fcmp = fcmp uno float 0.000000e+00, 0.000000e+00 + %ivnext = add nsw i32 %iv, 1 + %cnd = icmp sgt i32 %iv, 142 + br i1 %cnd, label %exit, label %loop + +exit: ; preds = %loop + ret void +}