[PATCH] D38656: [CGExprScalar] In EmitCompare trunc the result if it has different type as E->getType()
This revision was automatically updated to reflect the committed changes. Closed by commit rL315358: [CGExprScalar] In EmitCompare trunc the result if it has different type as E… (authored by Carrot). Changed prior to commit: https://reviews.llvm.org/D38656?vs=118236=118464#toc Repository: rL LLVM https://reviews.llvm.org/D38656 Files: cfe/trunk/lib/CodeGen/CGExprScalar.cpp cfe/trunk/test/CodeGen/ppc-vector-compare.cc Index: cfe/trunk/test/CodeGen/ppc-vector-compare.cc === --- cfe/trunk/test/CodeGen/ppc-vector-compare.cc +++ cfe/trunk/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 + +// CHECK-LABEL: @_Z5test1Dv8_tS_ +// CHECK: @llvm.ppc.altivec.vcmpequh.p +bool test1(vector unsigned short v1, vector unsigned short v2) { + return v1 == v2; +} + Index: cfe/trunk/lib/CodeGen/CGExprScalar.cpp === --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp +++ cfe/trunk/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(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()); } Index: cfe/trunk/test/CodeGen/ppc-vector-compare.cc === --- cfe/trunk/test/CodeGen/ppc-vector-compare.cc +++ cfe/trunk/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 + +// CHECK-LABEL: @_Z5test1Dv8_tS_ +// CHECK: @llvm.ppc.altivec.vcmpequh.p +bool test1(vector unsigned short v1, vector unsigned short v2) { + return v1 == v2; +} + Index: cfe/trunk/lib/CodeGen/CGExprScalar.cpp === --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp +++ cfe/trunk/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(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()); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38656: [CGExprScalar] In EmitCompare trunc the result if it has different type as E->getType()
Carrot added a comment. In https://reviews.llvm.org/D38656#892740, @nemanjai wrote: > In https://reviews.llvm.org/D38656#892072, @Carrot wrote: > > > I worked on a similar bug as 31161, and then found this one, it should be > > same as in comment7. > > What is the current status of the work on that bug? > > > No one has had time to finalize a fix to it. Please go ahead with this patch. > If this patch indeed fixes the bug, please close it. This patch fixes the second part of bug 31161 described in comment7. I will check it in soon. For the first part of the bug, I will retest your patch in comment1, plus incorrect handling of type long in our case, and then send it out. https://reviews.llvm.org/D38656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38656: [CGExprScalar] In EmitCompare trunc the result if it has different type as E->getType()
nemanjai added a comment. In https://reviews.llvm.org/D38656#892072, @Carrot wrote: > I worked on a similar bug as 31161, and then found this one, it should be > same as in comment7. > What is the current status of the work on that bug? No one has had time to finalize a fix to it. Please go ahead with this patch. If this patch indeed fixes the bug, please close it. https://reviews.llvm.org/D38656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38656: [CGExprScalar] In EmitCompare trunc the result if it has different type as E->getType()
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 + +// 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(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()); } 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 + +// 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(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()); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38656: [CGExprScalar] In EmitCompare trunc the result if it has different type as E->getType()
majnemer added inline comments. Comment at: lib/CodeGen/CGExprScalar.cpp:3223-3224 + // crash later. + llvm::IntegerType *ResultTy = + dyn_cast(Result->getType()); + if ((ResultTy->getBitWidth() > 1) && Is this clang-format'd ? Comment at: lib/CodeGen/CGExprScalar.cpp:3224 + llvm::IntegerType *ResultTy = + dyn_cast(Result->getType()); + if ((ResultTy->getBitWidth() > 1) && You are unconditionally dereferencing the result of a dyn_cast. You are either missing a null-check or this should be a cast<> Comment at: lib/CodeGen/CGExprScalar.cpp:3225-3226 + dyn_cast(Result->getType()); + if ((ResultTy->getBitWidth() > 1) && + (E->getType() == CGF.getContext().BoolTy)) +Result = Builder.CreateTrunc(Result, Builder.getInt1Ty()); Extra parens. https://reviews.llvm.org/D38656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38656: [CGExprScalar] In EmitCompare trunc the result if it has different type as E->getType()
Carrot added a comment. I worked on a similar bug as 31161, and then found this one, it should be same as in comment7. What is the current status of the work on that bug? https://reviews.llvm.org/D38656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38656: [CGExprScalar] In EmitCompare trunc the result if it has different type as E->getType()
nemanjai added a comment. I assume this also fixes https://bugs.llvm.org/show_bug.cgi?id=31161? https://reviews.llvm.org/D38656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits