This is an archive of the discontinued LLVM Phabricator instance.

[MIPS GlobalISel] Select bitreverse
ClosedPublic

Authored by Petar.Avramovic on Dec 11 2019, 8:47 AM.

Details

Summary

G_BITREVERSE is generated from llvm.bitreverse.<type> intrinsics, clang
genrates these intrinsics from builtin_bitreverse32 and
builtin_bitreverse64.
Add lower and narrowscalar for G_BITREVERSE.
Lower G_BITREVERSE on MIPS32.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2019, 8:47 AM
Petar.Avramovic added a reviewer: arsenm.

Forgot to run regression tests for amd.

When I apply this one and D71362 to the master branch I get a couple of failed tests:

LLVM :: CodeGen/Mips/GlobalISel/legalizer/bitreverse.mir
LLVM :: CodeGen/Mips/GlobalISel/llvm-ir/bitreverse.ll

Should I apply any other patches before?

This patch needs only bswap, I just checked and it worked fine for me, what was the error?

I'll check again on my side tomorrow.

******************** TEST 'LLVM :: CodeGen/Mips/GlobalISel/llvm-ir/bitreverse.ll' FAILED ********************
Script:
--
: 'RUN: at line 2';   /home/simon/work/llvm/bld/bin/llc -O0 -mtriple=mipsel-linux-gnu -global-isel -verify-machineinstrs /home/simon/work/llvm/git/llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/bitreverse.ll -o -| /home/simon/work/llvm/bld/bin/FileCheck /home/simon/work/llvm/git/llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/bitreverse.ll -check-prefixes=MIPS32                                                                                                  
: 'RUN: at line 3';   /home/simon/work/llvm/bld/bin/llc -O0 -mtriple=mipsel-linux-gnu -global-isel -mattr=+mips32r2 -verify-machineinstrs /home/simon/work/llvm/git/llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/bitreverse.ll -o -|
/home/simon/work/llvm/bld/bin/FileCheck /home/simon/work/llvm/git/llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/bitreverse.ll -check-prefixes=MIPS32R2                                                                               
--
Exit Code: 1

Command Output (stderr):
--
/home/simon/work/llvm/git/llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/bitreverse.ll:20:16: error: MIPS32-NEXT: expected string not found in input                                                                                  
; MIPS32-NEXT: sll $3, $1, 4
               ^
<stdin>:34:2: note: scanning from here
 and $3, $1, $2
 ^
<stdin>:36:2: note: possible intended match here
 sll $1, $1, 4
 ^
/home/simon/work/llvm/git/llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/bitreverse.ll:89:16: error: MIPS32-NEXT: expected string not found in input                                                                                  
; MIPS32-NEXT: sll $3, $1, 4
               ^
<stdin>:89:2: note: scanning from here
 and $3, $1, $2
 ^
<stdin>:91:2: note: possible intended match here
 sll $1, $1, 4
 ^
nhaehnle removed a subscriber: nhaehnle.Dec 13 2019, 5:53 AM
This revision is now accepted and ready to land.Dec 27 2019, 6:10 AM
This revision was automatically updated to reflect the committed changes.

This change broke buildbots: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/21066.

I reverted it in 32cc14100e802fddd9f88e7a862250ce3108a583. Please always run ninja check-all before pushing.

Buildbot failures depend on compiler used to build clang.
Problem was in order which new MachineInstructions get inserted into MachineFunction.
Generated assembler does the same thing, but regression tests require consistent behavior regardless of compiler used.
In:

return B.buildOr(Dst, B.buildLShr(Ty, B.buildAnd(Ty, Src, MaskLoNTo0), C_N),
                 B.buildAnd(Ty, B.buildShl(Ty, Src, C_N), MaskLoNTo0));

it is important which method was executed first since they insert MachineInstructions into MachineFunction. Order of execution:
gcc

B.buildAnd(Ty, B.buildShl(Ty, Src, C_N), MaskLoNTo0)
B.buildLShr(Ty, B.buildAnd(Ty, Src, MaskLoNTo0), C_N)

clang

B.buildLShr(Ty, B.buildAnd(Ty, Src, MaskLoNTo0), C_N)
B.buildAnd(Ty, B.buildShl(Ty, Src, C_N), MaskLoNTo0)

recommit notes:
Introduce temporary variables in order to make sure instructions get inserted into MachineFunction in same order regardless of compiler used to build llvm.