[PATCH] D52263: [InstCombine] Handle vector compares in foldGEPIcmp()

Jesper Antonsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 19 06:44:42 PDT 2018


JesperAntonsson updated this revision to Diff 166117.
JesperAntonsson retitled this revision from "[InstCombine] Ignore vector compares in foldGEPIcmp()" to "[InstCombine] Handle vector compares in foldGEPIcmp()".
JesperAntonsson edited the summary of this revision.
JesperAntonsson added a comment.

Roman Lebedev commented with an elegant way to create varying integer values, so this patch makes use of that. Changed name of patch to reflect that we now handle rather than ignore vector icmps.


https://reviews.llvm.org/D52263

Files:
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  test/Transforms/InstCombine/pr38984.ll


Index: test/Transforms/InstCombine/pr38984.ll
===================================================================
--- /dev/null
+++ 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"
+
+ at 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> <i16 1, i16 1, i16 1, i16 1>
+  %10 = sext <4 x i16> %9 to <4 x i32>
+  ret void
+}
Index: lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -976,7 +976,8 @@
 
       if (NumDifferences == 0)   // SAME GEP?
         return replaceInstUsesWith(I, // No comparison is needed here.
-                             Builder.getInt1(ICmpInst::isTrueWhenEqual(Cond)));
+          Constant::getIntegerValue(I.getType(),
+                                    APInt(1, ICmpInst::isTrueWhenEqual(Cond))));
 
       else if (NumDifferences == 1 && GEPsInBounds) {
         Value *LHSV = GEPLHS->getOperand(DiffOperand);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52263.166117.patch
Type: text/x-patch
Size: 1840 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180919/803d9786/attachment.bin>


More information about the llvm-commits mailing list