[PATCH] D46379: [ConstantFold] Turn off expression simplification for vector type

Karl-Johan Karlsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 2 23:39:40 PDT 2018


Ka-Ka created this revision.
Ka-Ka added reviewers: majnemer, mkuper.

The getelementptr returns a vector of pointers, instead of a single
address, when one or more of its arguments is a vector. In such case it
is not possible to simplify the expression by inserting a bitcast of
operand(0) into the destination type, as it will create a bitcast
between different sizes.

The simplifications turned off in this patch was not intended for
vectorized types.


Repository:
  rL LLVM

https://reviews.llvm.org/D46379

Files:
  lib/IR/ConstantFold.cpp
  test/Transforms/LoopVectorize/X86/constant-fold.ll


Index: test/Transforms/LoopVectorize/X86/constant-fold.ll
===================================================================
--- /dev/null
+++ test/Transforms/LoopVectorize/X86/constant-fold.ll
@@ -0,0 +1,40 @@
+; RUN: opt -loop-vectorize -S -mtriple=x86_64-- -o - %s | FileCheck %s
+
+%rec8 = type { i16 }
+
+ at a = global [1 x %rec8] zeroinitializer
+ at b = global [2 x i16*] zeroinitializer
+
+
+define void @f1() {
+  %_tmp112 = icmp slt i16 0, 2
+  br i1 %_tmp112, label %bb2.lr.ph, label %bb3
+
+bb2.lr.ph:
+  br label %bb2
+
+bb2:
+  %c.1.0 = phi i16 [ 0, %bb2.lr.ph ], [ %_tmp9, %bb2 ]
+  %_tmp1 = zext i16 0 to i64
+  %_tmp2 = getelementptr [1 x %rec8], [1 x %rec8]* @a, i16 0, i64 %_tmp1
+  %_tmp4 = bitcast %rec8* %_tmp2 to i16*
+  %_tmp6 = sext i16 %c.1.0 to i64
+  %_tmp7 = getelementptr [2 x i16*], [2 x i16*]* @b, i16 0, i64 %_tmp6
+  store i16* %_tmp4, i16** %_tmp7
+  %_tmp9 = add nsw i16 %c.1.0, 1
+  %_tmp11 = icmp slt i16 %_tmp9, 2
+  br i1 %_tmp11, label %bb2, label %bb1.bb3_crit_edge
+
+bb1.bb3_crit_edge:
+  br label %bb3
+
+bb3:
+  ret void
+}
+; CHECK: vector.body:
+; CHECK: [[BITC:%.*]] = bitcast i16** [[IN:%.*]] to <2 x i16*>*
+
+; Check that we don't generate a faulty bitcast that cast between different sizes
+; CHECK-NOT: store <2 x i16*> bitcast ([1 x %rec8]* @a to <2 x i16*>), <2 x i16*>* [[BITC]]
+
+; CHECK: store <2 x i16*> <i16* getelementptr inbounds (%rec8, %rec8* extractelement (<2 x %rec8*> getelementptr ([1 x %rec8], [1 x %rec8]* @a, <2 x i16> zeroinitializer, <2 x i64> zeroinitializer), i32 0), i32 0, i32 0), i16* getelementptr inbounds (%rec8, %rec8* extractelement (<2 x %rec8*> getelementptr ([1 x %rec8], [1 x %rec8]* @a, <2 x i16> zeroinitializer, <2 x i64> zeroinitializer), i32 1), i32 0, i32 0)>, <2 x i16*>* [[BITC]]
Index: lib/IR/ConstantFold.cpp
===================================================================
--- lib/IR/ConstantFold.cpp
+++ lib/IR/ConstantFold.cpp
@@ -534,7 +534,8 @@
 
   // If the cast operand is a constant expression, there's a few things we can
   // do to try to simplify it.
-  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
+  ConstantExpr *CE = dyn_cast<ConstantExpr>(V);
+  if (CE && !DestTy->isVectorTy()) {
     if (CE->isCast()) {
       // Try hard to fold cast of cast because they are often eliminable.
       if (unsigned newOpc = foldConstantCastPair(opc, CE, DestTy))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46379.144985.patch
Type: text/x-patch
Size: 2373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180503/ea24d4d4/attachment.bin>


More information about the llvm-commits mailing list