xcore backend: bug when calling countLeadingZeros()
Duncan Sands
duncan.sands at gmail.com
Tue Jul 2 06:45:57 PDT 2013
Hi Robert,
On 02/07/13 14:51, Robert Lytton wrote:
> 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
are other uses of these routines OK? Did you audit the entire codebase?
Thanks, Duncan.
>
> 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;
> +}
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list