[PATCH] D46656: [Builtins] Improve the IR emitted for MSVC compatible rotr/rotl builtins to match what the middle and backends understand
    Craig Topper via Phabricator via cfe-commits 
    cfe-commits at lists.llvm.org
       
    Wed May  9 12:04:24 PDT 2018
    
    
  
craig.topper created this revision.
craig.topper added a reviewer: spatel.
Currently we emit something like
rotl(x, n) {
n &= bitwidth -1;
return n != 0 ? ((x << n) | (x >> (bitwidth - n)) : x;
}
We use a select to avoid the undefined behavior on the (bitwidth - n) shift.
The middle and backend don't really recognize this as a rotate and end up emitting a cmov or control flow because of the select.
A better pattern is (x << (n & mask)) | (x << (-n & mask))  where mask is bitwidth - 1.
Fixes the main complaint in PR37387. There's still some work to be done if the user writes that sequence directly on a short or char where type promotion rules can prevent it from being recognized. The builtin is emitting direct IR with unpromoted types so that isn't a problem for it.
https://reviews.llvm.org/D46656
Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/ms-intrinsics-rotations.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46656.145979.patch
Type: text/x-patch
Size: 13129 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180509/3c7ac952/attachment.bin>
    
    
More information about the cfe-commits
mailing list