From 8114ee377bf83ebf5d90174a4ba8b2434b782d74 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 5 Oct 2017 07:59:11 +0000 Subject: [PATCH] [InstCombine] Fix a vector splat handling bug in transformZExtICmp. We were using an i1 type and then zero extending to a vector. Instead just create the 0/1 directly as a ConstantInt with the correct type. No need to ask ConstantExpr to zero extend for us. This bug is a bit tricky to hit because it requires us to visit a zext of an icmp that would normally be simplified to true/false, but that icmp hasnt' been visited yet. In the test case this zext and icmp were created by visiting a udiv and due to worklist ordering we got to the zext first. Fixes PR34841. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314971 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineCasts.cpp | 4 +--- test/Transforms/InstCombine/div.ll | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp index f7be0f9bc3f..5e4fd8c2656 100644 --- a/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -818,9 +818,7 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *ICI, ZExtInst &CI, if (!Op1CV->isNullValue() && (*Op1CV != KnownZeroMask)) { // (X&4) == 2 --> false // (X&4) != 2 --> true - Constant *Res = ConstantInt::get(Type::getInt1Ty(CI.getContext()), - isNE); - Res = ConstantExpr::getZExt(Res, CI.getType()); + Constant *Res = ConstantInt::get(CI.getType(), isNE); return replaceInstUsesWith(CI, Res); } diff --git a/test/Transforms/InstCombine/div.ll b/test/Transforms/InstCombine/div.ll index b323e31e63e..42da1382f97 100644 --- a/test/Transforms/InstCombine/div.ll +++ b/test/Transforms/InstCombine/div.ll @@ -553,3 +553,12 @@ define i32 @shrink_no3(i16 %x) { ret i32 %div } +; This previously crashed when trying to simplify the zext/icmp this becomes. +define <2 x i8> @PR34841(<2 x i8> %x) { +; CHECK-LABEL: @PR34841( +; CHECK-NEXT: ret <2 x i8> zeroinitializer +; + %neg = and <2 x i8> %x, + %div = udiv <2 x i8> , %neg + ret <2 x i8> %div +} -- 2.49.0