[PATCH] D38656: [CGExprScalar] In EmitCompare trunc the result if it has different type as E->getType()

Guozhi Wei via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 9 10:52:58 PDT 2017


Carrot updated this revision to Diff 118236.
Carrot marked 3 inline comments as done.

https://reviews.llvm.org/D38656

Files:
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGen/ppc-vector-compare.cc


Index: test/CodeGen/ppc-vector-compare.cc
===================================================================
--- test/CodeGen/ppc-vector-compare.cc
+++ test/CodeGen/ppc-vector-compare.cc
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -triple powerpc64-unknown-unknown -emit-llvm %s \
+// RUN:            -o - | FileCheck %s
+
+#include <altivec.h>
+
+// CHECK-LABEL: @_Z5test1Dv8_tS_
+// CHECK: @llvm.ppc.altivec.vcmpequh.p
+bool test1(vector unsigned short v1, vector unsigned short v2) {
+  return v1 == v2;
+}
+
Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -3214,6 +3214,16 @@
       Value *CR6Param = Builder.getInt32(CR6);
       llvm::Function *F = CGF.CGM.getIntrinsic(ID);
       Result = Builder.CreateCall(F, {CR6Param, FirstVecArg, SecondVecArg});
+
+      // The result type of intrinsic may not be same as E->getType().
+      // If E->getType() is not BoolTy, EmitScalarConversion will do the
+      // conversion work. If E->getType() is BoolTy, EmitScalarConversion will
+      // do nothing, if ResultTy is not i1 at the same time, it will cause
+      // crash later.
+      llvm::IntegerType *ResultTy = cast<llvm::IntegerType>(Result->getType());
+      if (ResultTy->getBitWidth() > 1 &&
+          E->getType() == CGF.getContext().BoolTy)
+        Result = Builder.CreateTrunc(Result, Builder.getInt1Ty());
       return EmitScalarConversion(Result, CGF.getContext().BoolTy, E->getType(),
                                   E->getExprLoc());
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38656.118236.patch
Type: text/x-patch
Size: 1615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171009/1cf50221/attachment.bin>


More information about the cfe-commits mailing list