]> granicus.if.org Git - llvm/commitdiff
[InstCombine] Support weird size element types in dyn_castNegVal.
authorCraig Topper <craig.topper@gmail.com>
Tue, 11 Apr 2017 05:42:47 +0000 (05:42 +0000)
committerCraig Topper <craig.topper@gmail.com>
Tue, 11 Apr 2017 05:42:47 +0000 (05:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299915 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/2008-05-22-NegValVector.ll
test/Transforms/InstCombine/rem.ll

index 398b49748ecdec330314eb5a10e17d758a9d0590..3c6f07e7fddee9760e249a1b1715a847c7dadcb5 100644 (file)
@@ -726,6 +726,10 @@ Value *InstCombiner::dyn_castNegVal(Value *V) const {
     if (C->getType()->getElementType()->isIntegerTy())
       return ConstantExpr::getNeg(C);
 
+  if (ConstantVector *C = dyn_cast<ConstantVector>(V))
+    if (C->getType()->getElementType()->isIntegerTy())
+      return ConstantExpr::getNeg(C);
+
   return nullptr;
 }
 
index bf92faf2fec58d67127c16e3f21a036790240f27..58259be8bc9236383cebb27f589e242bb4d7dbe5 100644 (file)
@@ -6,3 +6,9 @@ define <3 x i8> @f(<3 x i8> %a) {
   ret <3 x i8> %B
 }
 
+define <3 x i4> @g(<3 x i4> %a) {
+  %A = sub <3 x i4> zeroinitializer, %a
+  %B = mul <3 x i4> %A, <i4 5, i4 5, i4 5>
+  ret <3 x i4> %B
+}
+
index 75ac27c9c853919504cac8b70bebf9a358cc6e0c..7a7a134db9c5d42e716482491dab3bd49ca4536d 100644 (file)
@@ -57,12 +57,11 @@ define i5 @biggest_divisor(i5 %x) {
   ret i5 %rem
 }
 
-; TODO: Should vector subtract of constant be canonicalized to add?
 define <2 x i4> @big_divisor_vec(<2 x i4> %x) {
 ; CHECK-LABEL: @big_divisor_vec(
-; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult <2 x i4> %x, <i4 -3, i4 -3>
-; CHECK-NEXT:    [[TMP2:%.*]] = sub <2 x i4> %x, <i4 -3, i4 -3>
-; CHECK-NEXT:    [[REM:%.*]] = select <2 x i1> [[TMP1]], <2 x i4> %x, <2 x i4> [[TMP2]]
+; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult <2 x i4> [[X:%.*]], <i4 -3, i4 -3>
+; CHECK-NEXT:    [[TMP2:%.*]] = add <2 x i4> [[X]], <i4 3, i4 3>
+; CHECK-NEXT:    [[REM:%.*]] = select <2 x i1> [[TMP1]], <2 x i4> [[X]], <2 x i4> [[TMP2]]
 ; CHECK-NEXT:    ret <2 x i4> [[REM]]
 ;
   %rem = urem <2 x i4> %x, <i4 13, i4 13>