OSDN Git Service

[XCore] Fix instruction selection for zext, mkmsk instructions.
authorRichard Osborne <richard@xmos.com>
Tue, 2 Jul 2013 14:46:34 +0000 (14:46 +0000)
committerRichard Osborne <richard@xmos.com>
Tue, 2 Jul 2013 14:46:34 +0000 (14:46 +0000)
r182680 replaced CountLeadingZeros_32 with a template function
countLeadingZeros that relies on using the correct argument type to give
the right result. The type passed in the XCore backend after this
revision was incorrect in a couple of places.

Patch by Robert Lytton.

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

lib/Target/XCore/XCoreISelDAGToDAG.cpp
lib/Target/XCore/XCoreInstrInfo.td
test/CodeGen/XCore/constants.ll
test/CodeGen/XCore/zext.ll [new file with mode: 0644]

index 768cba6..e28f84f 100644 (file)
@@ -115,7 +115,7 @@ SDNode *XCoreDAGToDAGISel::Select(SDNode *N) {
     if (immMskBitp(N)) {
       // Transformation function: get the size of a mask
       // Look for the first non-zero bit
-      SDValue MskSize = getI32Imm(32 - countLeadingZeros(Val));
+      SDValue MskSize = getI32Imm(32 - countLeadingZeros((uint32_t)Val));
       return CurDAG->getMachineNode(XCore::MKMSK_rus, dl,
                                     MVT::i32, MskSize);
     }
index e06419a..be152ae 100644 (file)
@@ -84,7 +84,7 @@ def msksize_xform : SDNodeXForm<imm, [{
   // Transformation function: get the size of a mask
   assert(isMask_32(N->getZExtValue()));
   // look for the first non-zero bit
-  return getI32Imm(32 - countLeadingZeros(N->getZExtValue()));
+  return getI32Imm(32 - countLeadingZeros((uint32_t)N->getZExtValue()));
 }]>;
 
 def neg_xform : SDNodeXForm<imm, [{
index cad1a21..1e064f3 100644 (file)
@@ -9,3 +9,11 @@ define i32 @f() {
 entry:
        ret i32 12345678
 }
+
+define i32 @g() {
+entry:
+; CHECK: g:
+; CHECK: mkmsk r0, 1
+; CHECK: retsp 0
+  ret i32 1;
+}
diff --git a/test/CodeGen/XCore/zext.ll b/test/CodeGen/XCore/zext.ll
new file mode 100644 (file)
index 0000000..32abfca
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: llc -march=xcore < %s | FileCheck %s
+
+define i32 @f(i1 %a) {
+entry:
+; CHECK: f
+; CHECK: zext r0, 1
+; CHECK: retsp 0
+  %b= zext i1 %a to i32
+  ret i32 %b
+}