This is an archive of the discontinued LLVM Phabricator instance.

[ARM64]Scalar right shift uint64_t by 64 generates incorrect result.
Needs ReviewPublic

Authored by HaoLiu on May 13 2014, 11:50 PM.

Details

Reviewers
t.p.northover
Summary

Hi Tim and other reviewers,

In the front end CGBuiltin.cpp, we generate incorrect code for scalar right shift uint64_t by 64, which is incorrectly transferred into "LSR X0, #63".
So when we try to right shift 0xf000000000000000 by 64, the result is 0x1, but it should be 0x0.

As according to LLVM reference, the right shift amount of i64 should be [0, 63], we can't generate such IR like "lshr i64 %tmp, 64". To fix this problem, this patch just return 0 result when the shift amount is 64.

Ask for code review.

Thanks,
-Hao

Diff Detail

Event Timeline

HaoLiu updated this revision to Diff 9375.May 13 2014, 11:50 PM
HaoLiu retitled this revision from to [ARM64]Scalar right shift uint64_t by 64 generates incorrect result..
HaoLiu updated this object.
HaoLiu edited the test plan for this revision. (Show Details)
HaoLiu added a reviewer: t.p.northover.
HaoLiu added a subscriber: Unknown Object (MLST).

Hi Hao,

This patch looks fine. One thing I did notice:

+// CHECK-AArch64-LABEL: test_vsrad_n_u64_2

I don't actually know if FileCheck is case insensitive for CHECK lines, so I don't know if this line is firing? If you could correct the capitalization anyway it LGTM.

Cheers,

James

-----Original Message-----
From: cfe-commits-bounces@cs.uiuc.edu [mailto:cfe-commits-
bounces@cs.uiuc.edu] On Behalf Of Hao Liu
Sent: 14 May 2014 07:51
To: Hao Liu; t.p.northover@gmail.com
Cc: cfe-commits@cs.uiuc.edu
Subject: [PATCH] [ARM64]Scalar right shift uint64_t by 64 generates incorrect
result.

Hi t.p.northover,

Hi Tim and other reviewers,

In the front end CGBuiltin.cpp, we generate incorrect code for scalar right
shift uint64_t by 64, which is incorrectly transferred into "LSR X0, #63".
So when we try to right shift 0xf000000000000000 by 64, the result is 0x1, but
it should be 0x0.

As according to LLVM reference, the right shift amount of i64 should be [0,
63], we can't generate such IR like "lshr i64 %tmp, 64". To fix this problem,
this patch just return 0 result when the shift amount is 64.

Ask for code review.

Thanks,
-Hao

http://reviews.llvm.org/D3755

Files:

lib/CodeGen/CGBuiltin.cpp
test/CodeGen/aarch64-neon-intrinsics.c
HaoLiu updated this revision to Diff 9377.May 14 2014, 1:25 AM

Hi James,

Thanks for noticing this not easy to be found problem. FileCheck is indeed case sensitive. It is strange that the old test can still pass, which is because that line is ignored by FileCheck and it is only like a comment.

Anyway, I've fix this problem by the attached patch. And I'll commit it soon.

Thanks,
-Hao

lib/CodeGen/CGBuiltin.cpp
5583

The shift amount is always in range [0, 63] for left shift. If we give a number not in that range, clang will report an error. So don't need to std::min with 63.