[llvm-commits] [llvm] r125393 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Transforms/InstCombine/bitcast-vec-uniform.ll test/Transforms/InstCombine/fold-vector-select.ll

Rotem, Nadav nadav.rotem at intel.com
Sun Feb 13 07:16:01 PST 2011


Hi Benjamin, 

Thank you for catching this.  

The patch below fixes the problem. If it looks good to you I will commit it. 

Thanks, 
Nadav

Details:
1. Added a test to reproduce the problem.
2. Added a check that the vector is of integer type. 


Index: ../llvm/test/Transforms/InstCombine/bitcast-vec-uniform.ll
===================================================================
--- ../llvm/test/Transforms/InstCombine/bitcast-vec-uniform.ll  (revision 125450)
+++ ../llvm/test/Transforms/InstCombine/bitcast-vec-uniform.ll  (working copy)
@@ -1,14 +1,30 @@
-; RUN: opt < %s -instcombine -S | not grep bitcast
+; RUN: opt < %s -instcombine -S | FileCheck %s

+; CHECK: @a
+; CHECK-NOT: bitcast
+; CHECK: ret
 define <4 x i32> @a(<1 x i64> %y) {
   %c = bitcast <2 x i64> <i64 0, i64 0> to <4 x i32>
   ret <4 x i32> %c
 }

+; CHECK: @b
+; CHECK-NOT: bitcast
+; CHECK: ret
+
 define <4 x i32> @b(<1 x i64> %y) {
   %c = bitcast <2 x i64> <i64 -1, i64 -1> to <4 x i32>
   ret <4 x i32> %c
 }

+; CHECK: @foo
+; CHECK: bitcast

+; from MultiSource/Benchmarks/Bullet
+define <2 x float> @foo() {
+  %cast = bitcast i64 -1 to <2 x float>
+  ret <2 x float> %cast
+}


Index: ../llvm/lib/VMCore/ConstantFold.cpp
===================================================================
--- ../llvm/lib/VMCore/ConstantFold.cpp (revision 125450)
+++ ../llvm/lib/VMCore/ConstantFold.cpp (working copy)
@@ -43,7 +43,8 @@
 static Constant *BitCastConstantVector(ConstantVector *CV,
                                        const VectorType *DstTy) {

-  if (CV->isAllOnesValue()) return Constant::getAllOnesValue(DstTy);
+  if (CV->isAllOnesValue() && DstTy->getElementType()->isIntegerTy())
+      return Constant::getAllOnesValue(DstTy);
   if (CV->isNullValue()) return Constant::getNullValue(DstTy);




-----Original Message-----
From: Benjamin Kramer [mailto:benny.kra at googlemail.com] 
Sent: Sunday, February 13, 2011 16:25
To: Rotem, Nadav
Cc: llvm-commits at cs.uiuc.edu
Subject: Re: [llvm-commits] [llvm] r125393 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Transforms/InstCombine/bitcast-vec-uniform.ll test/Transforms/InstCombine/fold-vector-select.ll


On 11.02.2011, at 20:37, Nadav Rotem wrote:

> Author: nadav
> Date: Fri Feb 11 13:37:55 2011
> New Revision: 125393
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=125393&view=rev
> Log:
> Fix 9173.
> 
> Add more folding patterns to constant expressions of vector selects and vector
> bitcasts.
> 
> 
> Added:
>    llvm/trunk/test/Transforms/InstCombine/bitcast-vec-uniform.ll   (with props)
>    llvm/trunk/test/Transforms/InstCombine/fold-vector-select.ll   (with props)
> Modified:
>    llvm/trunk/lib/VMCore/ConstantFold.cpp
> 
> Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=125393&r1=125392&r2=125393&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
> +++ llvm/trunk/lib/VMCore/ConstantFold.cpp Fri Feb 11 13:37:55 2011
> @@ -42,6 +42,10 @@
> /// input vector constant are all simple integer or FP values.
> static Constant *BitCastConstantVector(ConstantVector *CV,
>                                        const VectorType *DstTy) {
> +
> +  if (CV->isAllOnesValue()) return Constant::getAllOnesValue(DstTy);
> +  if (CV->isNullValue()) return Constant::getNullValue(DstTy);
> +

Hi Nadav,

it looks like this change caused a crash in MultiSource/Benchmarks/Bullet in the test-suite,
here's a reduced test case:

define <2 x float> @foo() {
  %cast = bitcast i64 -1 to <2 x float>
  ret <2 x float> %cast
}

the test hits an assertion with "opt -std-compile-opts" because Constant::getAllOnesValue
doesn't know how to handle floats.

- Benjamin
---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.





More information about the llvm-commits mailing list