xcore backend: bug when calling countLeadingZeros()

Robert Lytton robert at xmos.com
Tue Jul 2 05:51:55 PDT 2013


Hi,

commit b955b0de : "Replace Count{Leading,Trailing}Zeros_{32,64} with count{Leading,Trailing}Zeros"
Added bug to XCore backend.

The type past to countLeadingZeros() now needs to be explicitly cast to 32bit

Below is the patch:
    llvm/lib/Target/XCore/XCoreISelDAGToDAG.cpp
    llvm/lib/Target/XCore/XCoreInstrInfo.td
and test:
    llvm/test/CodeGen/XCore/zext.ll

robert


--- llvm/lib/Target/XCore/XCoreISelDAGToDAG.cpp
+++ llvm/lib/Target/XCore/XCoreISelDAGToDAG.cpp
@@ -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);
     }


--- llvm/lib/Target/XCore/XCoreInstrInfo.td
+++ llvm/lib/Target/XCore/XCoreInstrInfo.td
@@ -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, [{


--- /dev/null
+++ llvm/test/CodeGen/XCore/zext.ll
@@ -0,0 +1,17 @@
+; RUN: llc -march=xcore < %s | FileCheck %s
+;; countLeadingZeros() must be past 32bit types
+
+define i32 @f(i1 %a) {
+entry:
+; CHECK: zext r0, 1
+; CHECK: retsp 0
+  %b= zext i1 %a to i32
+  ret i32 %b
+}
+
+define i32 @g() {
+entry:
+; CHECK: mkmsk r0, 1
+; CHECK: retsp 0
+  ret i32 1;
+}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130702/368d9bcf/attachment.html>


More information about the llvm-commits mailing list