Apply a patch by Micah Villmow to fix AsmParser to accept vector
authorDan Gohman <gohman@apple.com>
Sat, 14 Mar 2009 17:09:17 +0000 (17:09 +0000)
committerDan Gohman <gohman@apple.com>
Sat, 14 Mar 2009 17:09:17 +0000 (17:09 +0000)
shift constant expressions, and add support for folding vector
shift constant expressions. This fixes PR3802.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67010 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp
lib/VMCore/Constants.cpp
test/Assembler/vector-shift.ll

index f2847112afcb265539977e434c5b48cbe2f0e6fc..7e4902fd56354fba2aec096905903987f76b8492 100644 (file)
@@ -832,6 +832,12 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
         return EvalVectorOp(CP1, CP2, VTy, ConstantExpr::getOr);
       case Instruction::Xor: 
         return EvalVectorOp(CP1, CP2, VTy, ConstantExpr::getXor);
+      case Instruction::LShr:
+        return EvalVectorOp(CP1, CP2, VTy, ConstantExpr::getLShr);
+      case Instruction::AShr:
+        return EvalVectorOp(CP1, CP2, VTy, ConstantExpr::getAShr);
+      case Instruction::Shl:
+        return EvalVectorOp(CP1, CP2, VTy, ConstantExpr::getShl);
       }
     }
   }
index 0be2811e3548ff2eba5e8c1a309b7eb01e22f431..ed1e04ad547ed24082618216cf65a150964bcd1a 100644 (file)
@@ -2095,7 +2095,7 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
   case Instruction::LShr:
   case Instruction::AShr:
     assert(C1->getType() == C2->getType() && "Op types should be identical!");
-    assert(C1->getType()->isInteger() &&
+    assert(C1->getType()->isIntOrIntVector() &&
            "Tried to create a shift operation on a non-integer type!");
     break;
   default:
index 3b2c07c903577ac0905f375db67744b05a639e5d..1850e66e8edce228aa5fbe24a6dce115f80f4f24 100644 (file)
@@ -1,6 +1,6 @@
-; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | grep shl
-; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | grep ashr
-; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | grep lshr
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | grep shl | count 1
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | grep ashr | count 1
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | grep lshr | count 1
 
 define <4 x i32> @foo(<4 x i32> %a, <4 x i32> %b) nounwind  {
 entry:
@@ -19,3 +19,14 @@ entry:
        %cmp = ashr <4 x i32> %a, %b            ; <4 x i32> [#uses=1]
        ret <4 x i32> %cmp
 }
+
+; Constant expressions: these should be folded.
+define <2 x i64> @foo_ce() nounwind {
+  ret <2 x i64> shl (<2 x i64> <i64 5, i64 6>, <2 x i64> <i64 3, i64 5>)
+}
+define <2 x i64> @bar_ce() nounwind {
+  ret <2 x i64> lshr (<2 x i64> <i64 340, i64 380>, <2 x i64> <i64 3, i64 5>)
+}
+define <2 x i64> @baz_ce() nounwind {
+  ret <2 x i64> ashr (<2 x i64> <i64 573, i64 411>, <2 x i64> <i64 3, i64 5>)
+}