From 719fa055d0499e8f0e79ea579c2da1eb61dfa2f1 Mon Sep 17 00:00:00 2001 From: Jesper Antonsson Date: Thu, 20 Sep 2018 13:37:28 +0000 Subject: [PATCH] [InstCombine] Handle vector compares in foldGEPIcmp() Summary: This is to fix PR38984 "InstCombine assertion at vector gep/icmp folding": https://bugs.llvm.org/show_bug.cgi?id=38984 Reviewers: majnemer, spatel, lattner, lebedev.ri Reviewed By: lebedev.ri Subscribers: lebedev.ri, llvm-commits Differential Revision: https://reviews.llvm.org/D52263 llvm-svn: 342647 --- .../Transforms/InstCombine/InstCombineCompares.cpp | 2 +- llvm/test/Transforms/InstCombine/pr38984.ll | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Transforms/InstCombine/pr38984.ll diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 0cb92e0..dd3fed7 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -976,7 +976,7 @@ Instruction *InstCombiner::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, if (NumDifferences == 0) // SAME GEP? return replaceInstUsesWith(I, // No comparison is needed here. - Builder.getInt1(ICmpInst::isTrueWhenEqual(Cond))); + ConstantInt::get(I.getType(), ICmpInst::isTrueWhenEqual(Cond))); else if (NumDifferences == 1 && GEPsInBounds) { Value *LHSV = GEPLHS->getOperand(DiffOperand); diff --git a/llvm/test/Transforms/InstCombine/pr38984.ll b/llvm/test/Transforms/InstCombine/pr38984.ll new file mode 100644 index 0000000..2da2f9f --- /dev/null +++ b/llvm/test/Transforms/InstCombine/pr38984.ll @@ -0,0 +1,25 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -instcombine -S | FileCheck %s +target datalayout = "p:16:16" + +@offsets = external dso_local global [4 x i16], align 1 + +define void @PR38984() { +; CHECK-LABEL: @PR38984( +; CHECK-NEXT: entry: +; CHECK-NEXT: ret void +; +entry: + %0 = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 undef), align 1 + %1 = insertelement <4 x i16> undef, i16 %0, i32 3 + %2 = sub <4 x i16> zeroinitializer, %1 + %3 = sext <4 x i16> %2 to <4 x i32> + %4 = getelementptr inbounds i64, i64* null, <4 x i32> %3 + %5 = ptrtoint <4 x i64*> %4 to <4 x i32> + %6 = getelementptr inbounds i64, i64* null, <4 x i16> %2 + %7 = ptrtoint <4 x i64*> %6 to <4 x i32> + %8 = icmp eq <4 x i32> %5, %7 + %9 = select <4 x i1> %8, <4 x i16> zeroinitializer, <4 x i16> + %10 = sext <4 x i16> %9 to <4 x i32> + ret void +} -- 2.7.4