[llvm-bugs] [Bug 36253] New: llvm.bitreverse.i64 returns wrong value

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 6 12:30:23 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36253

            Bug ID: 36253
           Summary: llvm.bitreverse.i64 returns wrong value
           Product: libraries
           Version: 5.0
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: PowerPC
          Assignee: unassignedbugs at nondot.org
          Reporter: kai at redstar.de
                CC: llvm-bugs at lists.llvm.org

Created attachment 19818
  --> https://bugs.llvm.org/attachment.cgi?id=19818&action=edit
LLVM IR demonstring the problem.

The following code produces an unexpected output. It is a reduced version of
the following D code:

import ldc.intrinsics;
import core.stdc.stdio : printf;

int main()
{
    auto exp =  1UL << 63;
    printf("%lx\n", exp);
    auto arg = 1UL << 0;
    printf("%lx\n", arg);
    auto val = llvm_bitreverse(arg);
    printf("%lx\n", val);
    return exp != val;
}

LLVM IR:

source_filename = "bitop.d"
target datalayout = "e-m:e-i64:64-n32:64"
target triple = "powerpc64le-unknown-linux-gnu"

@.str = private unnamed_addr constant [5 x i8] c"%lx\0A\00"

declare signext i32 @printf(i8*, ...)

declare i64 @llvm.bitreverse.i64(i64)

define signext i32 @main(i32 signext %argc_arg, i8** %argv_arg) {
  %exp = alloca i64, align 8
  %arg = alloca i64, align 8
  %val = alloca i64, align 8
  store i64 -9223372036854775808, i64* %exp
  %1 = load i64, i64* %exp
  %2 = call signext i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x
i8], [5 x i8]* @.str, i32 0, i32 0), i64 %1)
  store i64 1, i64* %arg
  %3 = load i64, i64* %arg
  %4 = call signext i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x
i8], [5 x i8]* @.str, i32 0, i32 0), i64 %3)
  %5 = load i64, i64* %arg
  %6 = call i64 @llvm.bitreverse.i64(i64 %5)
  store i64 %6, i64* %val
  %7 = load i64, i64* %val
  %8 = call signext i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x
i8], [5 x i8]* @.str, i32 0, i32 0), i64 %7)
  %9 = load i64, i64* %exp
  %10 = load i64, i64* %val
  %11 = icmp ne i64 %9, %10
  %12 = zext i1 %11 to i32
  ret i32 %12
}

Compile and run:
llc -filetype=obj bitop.ll
gcc bitop.o -o bitop
./bitop
echo "Ret: $?"

Result:
8000000000000000
1
80000000
Ret: 1

If you change the line
    %6 = call i64 @llvm.bitreverse.i64(i64 %5)
to
    %6 = call i64 @llvm.bitreverse.i64(i64 %3)
or to
    %6 = call i64 @llvm.bitreverse.i64(i64 1)
then the expected output 

8000000000000000
1
8000000000000000
Ret: 0

is produced.

LLVM used:
ubuntu at ldc:/tmp/unittest$ /home/ubuntu/build-llvm/bin/llc --version
LLVM (http://llvm.org/):
  LLVM version 5.0.1git-6af15925d78
  DEBUG build with assertions.
  Default target: powerpc64le-unknown-linux-gnu
  Host CPU: pwr8

  Registered Targets:
    nvptx   - NVIDIA PTX 32-bit
    nvptx64 - NVIDIA PTX 64-bit
    ppc32   - PowerPC 32
    ppc64   - PowerPC 64
    ppc64le - PowerPC 64 LE

Environment:
ubuntu at ldc:/tmp/unittest$ uname -a
Linux ldc 4.13.0-32-generic #35-Ubuntu SMP Thu Jan 25 09:05:20 UTC 2018 ppc64le
ppc64le ppc64le GNU/Linux

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180206/f9a994db/attachment.html>


More information about the llvm-bugs mailing list