Giter Site home page Giter Site logo

jbush001 / nyuzitoolchain Goto Github PK

View Code? Open in Web Editor NEW
62.0 13.0 27.0 274.2 MB

Port of LLVM/Clang C compiler to Nyuzi parallel processor architecture

License: Other

Shell 0.04% Go 0.03% C++ 41.40% CMake 0.27% OCaml 0.07% Python 1.52% C 11.67% Objective-C 0.80% Assembly 11.00% LLVM 28.58% Perl 0.05% Emacs Lisp 0.01% Batchfile 0.01% Roff 0.01% Vim Script 0.01% HTML 4.24% Swift 0.01% CSS 0.02% Objective-C++ 0.20% Cuda 0.08%
llvm clang gpgpu toolchain compiler

nyuzitoolchain's Introduction

This is a toolchain for a parallel processor architecture called Nyuzi, based on LLVM. It includes a C/C++ compiler (clang), assembler, linker and debugger (lldb).

While this project includes a C/C++ compiler, the LLVM backend can support any language.

Questions or issues can be directed to the mailing list or... Chat at https://gitter.im/jbush001/NyuziProcessor

Building

The NyuziProcessor repository README has instructions for building this as well. These instructions are only necessary if you want to build this separately.

Required Software

The following sections describe how to install these packages.

  • gcc 4.8+ or Apple clang 4.2+
  • cmake 3.4.3+
  • python 2.7
  • libxml (including headers)
  • zlib (including headers)
  • bison 2.7+
  • flex 2.5+
  • swig 3.0.11+ (http://www.swig.org/) with python wrappers
  • libedit (http://thrysoee.dk/editline/)
  • ncurses
  • ninja 1.3+

Building on Linux

You can install required packages using the built-in package manager (apt-get, yum, etc). As LLVM needs newer versions of many packages, you should be on a recent version of your Linux distribution. Instructions are below are for Ubuntu (which must be on at least version 16). You may need to change the package names for other distributions:

sudo apt-get install libxml2-dev cmake gcc g++ python bison flex \
    zlib1g-dev swig python-dev libedit-dev libncurses5-dev ninja-build

git clone [email protected]:jbush001/NyuziToolchain.git
cd NyuziToolchain
mkdir build
cd build
cmake -G Ninja ..
ninja
sudo ninja install

Building on MacOS

On Mavericks and later, you can install the host command line compiler like this:

xcode-select --install

On earlier versions, you can download XCode from the app store. You will also need to install a package manager like Homebrew to get the remaining dependencies. Open a new terminal to do the build after installing Brew, because it installs alternate versions of some utilities and updates the PATH. Once you have done this:

brew install cmake bison swig sdl2 emacs ninja

git clone https://github.com/jbush001/NyuziToolchain.git
cd NyuziToolchain
mkdir build
cd build
cmake -G Ninja ..
ninja
sudo ninja install

Upgrading 'flex' using the package manager may cause build errors. I would recommend using the system supplied version.

Building on Windows

I have not tested this natively on Windows. Many of the libraries are already cross platform, so it should theoretically be possible.

Other Notes

  • The toolchain is installed into /usr/local/llvm-nyuzi/
  • The triple for this target is 'nyuzi-'.

Tests

Change PATH environment variable to include the binary directory (build/bin). This is only required for llvm-lit based tests. Run the tests as follows (assuming you are at the top of the project directory):

export PATH=<BUILDDIR>/build/bin:$PATH
llvm-lit test
llvm-lit tools/clang/test/CodeGen/
llvm-lit tools/lld/test/ELF/nyuzi-*

All tests should pass.

  • The command above for the LLD tests uses a wildcard to only run tests for the Nyuzi target. This is because many tests are architecture specific but don't specify a REQUIRES line in the file. They are assuming LLVM is built for all architectures, where I have modified the build files in this project to only build for Nyuzi.*

It is also useful to run the random test generator to validate the backend.

There is a set of whole-program tests in the NyuziProcessor repository test/whole-program Each test case is compiled and then run in the instruction set simulator, which checks the output for validity. This is similar to the test-suite project in LLVM. Instructions are in that directory.

In the same repository, there is also a test to validates the LLDB debugger by running a real program in the emulator: tests/tools/lldb

nyuzitoolchain's People

Contributors

adonut avatar cristina9209 avatar hatelix avatar jbush001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nyuzitoolchain's Issues

Comparison Inverted

The following code:

void  printneg(float f) {
    if (f < 0.0f)
        puts("neg\n");
    else
        puts("pos\n");
}

Prints "pos" when the number is negative. It's inserting an extra XOR:

    cmplt_f s0, s0, s1
    xor s0, s0, 1
    btrue s0, .LBB0_2

This is probably a regression after change 005c956

LLVM ERROR: Cannot select bitcast v16i32->v16i32

The following code

define <16 x i32> @fail() {
  %a = uitofp <16 x i1> undef to <16 x float>
  %b = bitcast <16 x float> %a to <16 x i32>
  ret <16 x i32> %b
}

Causes an assertion:

LLVM ERROR: Cannot select: t3: v16i32 = bitcast t11
  t11: v16i32 = vselect undef:v16i1, t10, t8
    t1: v16i1 = undef
    t10: v16f32 = NyuziISD::SPLAT t14
      t14: f32,ch = load<LD4[ConstantPool]> t0, TargetConstantPool:i32<float 1.000000e+00> 0, undef:i32
        t18: i32 = TargetConstantPool<float 1.000000e+00> 0
        t13: i32 = undef
    t8: v16f32 = NyuziISD::SPLAT t16
      t16: f32,ch = load<LD4[ConstantPool]> t0, TargetConstantPool:i32<float 0.000000e+00> 0, undef:i32
        t17: i32 = TargetConstantPool<float 0.000000e+00> 0
        t13: i32 = undef

This was generated by llvm-stress

fabs() causes compiler assert

The following code:

float test(float foo)
{
    return fabs(foo);
}

Causes an assertion:

fatal error: error in backend: Cannot select: 0x7fc0310c2ca0: f32 = select 0x7fc0310c30e0, 0x7fc0310c2310,
      0x7fc0310c2fd0 [ORD=2] [ID=14]
  0x7fc0310c30e0: i32 = setcc 0x7fc0310c2310, 0x7fc0310b2400, 0x7fc0310c2b90 [ORD=2] [ID=11]
    0x7fc0310c2310: f32,ch = CopyFromReg 0x7fc030c3ee20, 0x7fc0310c2200 [ORD=1] [ID=7]
      0x7fc0310c2200: f32 = Register %vreg0 [ID=1]
    0x7fc0310b2400: f32,ch = load 0x7fc030c3ee20, 0x7fc0310c2860, 0x7fc0310c2a80<LD4[ConstantPool]> [ID=8]
      0x7fc0310c2860: i32 = TargetConstantPool<float 0.000000e+00> 0 [ID=5]
      0x7fc0310c2a80: i32 = undef [ID=4]
    0x7fc0310c2b90: ch = setogt [ID=3]
  0x7fc0310c2310: f32,ch = CopyFromReg 0x7fc030c3ee20, 0x7fc0310c2200 [ORD=1] [ID=7]
    0x7fc0310c2200: f32 = Register %vreg0 [ID=1]
  0x7fc0310c2fd0: f32 = bitcast 0x7fc0310c2ec0 [ORD=2] [ID=13]
    0x7fc0310c2ec0: i32 = xor 0x7fc0310c2db0, 0x7fc0310b2510 [ORD=2] [ID=12]
      0x7fc0310c2db0: i32 = bitcast 0x7fc0310c2310 [ORD=2] [ID=10]
        0x7fc0310c2310: f32,ch = CopyFromReg 0x7fc030c3ee20, 0x7fc0310c2200 [ORD=1] [ID=7]
          0x7fc0310c2200: f32 = Register %vreg0 [ID=1]
      0x7fc0310b2510: i32,ch = load 0x7fc030c3ee20, 0x7fc0310c2420, 0x7fc0310c2a80<LD4[ConstantPool]> [ID=9]
        0x7fc0310c2420: i32 = TargetConstantPool<i32 -2147483648> 0 [ID=6]
        0x7fc0310c2a80: i32 = undef [ID=4]

Assertion failed: Binary operator types must match!

This program:

target triple = "nyuzi-none-none"

define void @autogen_SD25281() {
BB:
  %Cmp434 = fcmp ugt <8 x float> undef, undef
  br label %CF851

CF851:                                            ; preds = %CF851, %BB
  %E837 = extractelement <8 x i1> %Cmp434, i32 2
  br i1 %E837, label %CF851, label %CF859

CF859:                                            ; preds = %CF851
  ret void
}

Causes an assertion:

Assertion failed: (N1.getValueType() == N2.getValueType() && N1.getValueType() == VT && "Binary operator types must match!"), function getNode, file /Users/jeffbush/src/NyuziToolchain/lib/CodeGen/SelectionDAG/SelectionDAG.cpp, line 3826.
0  llc                      0x000000010c18864c llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  llc                      0x000000010c188bc9 PrintStackTraceSignalHandler(void*) + 25
2  llc                      0x000000010c184be9 llvm::sys::RunSignalHandlers() + 425
3  llc                      0x000000010c189062 SignalHandler(int) + 354
4  libsystem_platform.dylib 0x00007fff8cb2bbba _sigtramp + 26
5  libsystem_platform.dylib 0x00007fc7b780a3b0 _sigtramp + 718137360
6  libsystem_c.dylib        0x00007fff8c9b2420 abort + 129
7  libsystem_c.dylib        0x00007fff8c979893 basename_r + 0
8  llc                      0x000000010bf174bb llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDNodeFlags const*) + 2507
9  llc                      0x000000010abc6eff llvm::NyuziTargetLowering::LowerSETCC(llvm::SDValue, llvm::SelectionDAG&) const + 1999
10 llc                      0x000000010abc2c41 llvm::NyuziTargetLowering::LowerOperation(llvm::SDValue, llvm::SelectionDAG&) const + 593
11 llc                      0x000000010be09347 (anonymous namespace)::VectorLegalizer::LegalizeOp(llvm::SDValue) + 4183
12 llc                      0x000000010be07abd (anonymous namespace)::VectorLegalizer::Run() + 1437
13 llc                      0x000000010be074a2 llvm::SelectionDAG::LegalizeVectors() + 66
14 llc                      0x000000010bf8a3e6 llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 6566
15 llc                      0x000000010bf888fe llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&) + 270
16 llc                      0x000000010bf86ff2 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 5506
17 llc                      0x000000010bf840eb llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1643
18 llc                      0x000000010b236f31 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 449
19 llc                      0x000000010b73e1ff llvm::FPPassManager::runOnFunction(llvm::Function&) + 399
20 llc                      0x000000010b73e705 llvm::FPPassManager::runOnModule(llvm::Module&) + 117
21 llc                      0x000000010b73f4d4 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) + 2196
22 llc                      0x000000010b73e9c6 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 342
23 llc                      0x000000010b740201 llvm::legacy::PassManager::run(llvm::Module&) + 33
24 llc                      0x000000010ab83372 compileModule(char**, llvm::LLVMContext&) + 21810
25 llc                      0x000000010ab7d403 main + 2419
26 libdyld.dylib            0x00007fff8c91e255 start + 1
27 libdyld.dylib            0x0000000000000004 start + 1936596400

Assertion failed: Tried to create a shift operation on a non-integral type!

In the case where a shift operation is (incorrectly) attempted on a floating point value:

typedef float vecf16_t __attribute__((ext_vector_type(16)));

vecf16_t crash(vecf16_t number)
{
    return number >> 1;
}

Crashes with:

Assertion failed: ((getType()->isIntegerTy() || (getType()->isVectorTy() && cast<VectorType>(getType())->getElementType()->isIntegerTy())) && "Tried to create a shift operation on a non-integral type!"), function init, file /Users/jeffbush/src/NyuziToolchain/lib/IR/Instructions.cpp, line 2098.

Test CodeGen/Generic/donothing.ll fails

Recent regression, possibly during upstream integration:

Assertion failed: (MRI->getVRegDef(reg) && "Register use before def!"), function HandleVirtRegUse, file /Users/jeffbush/src/NyuziToolchain/lib/CodeGen/LiveVariables.cpp, line 133.
0  llc                      0x00000001084f489e llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 46
1  llc                      0x00000001084f5e69 PrintStackTraceSignalHandler(void*) + 25
2  llc                      0x00000001084f62be SignalHandler(int) + 590
3  libsystem_platform.dylib 0x00007fff97510f1a _sigtramp + 26
4  libsystem_platform.dylib 0x00007fff62d99764 _sigtramp + 3414722660
5  llc                      0x00000001084f5e8b raise + 27
6  llc                      0x00000001084f5f42 abort + 18
7  llc                      0x00000001084f5f21 __assert_rtn + 129
8  llc                      0x00000001079a7b14 llvm::LiveVariables::HandleVirtRegUse(unsigned int, llvm::MachineBasicBlock*, llvm::MachineInstr*) + 164
9  llc                      0x00000001079aa7f6 llvm::LiveVariables::runOnInstr(llvm::MachineInstr*, llvm::SmallVectorImpl<unsigned int>&) + 678
10 llc                      0x00000001079aad83 llvm::LiveVariables::runOnBlock(llvm::MachineBasicBlock*, unsigned int) + 867
11 llc                      0x00000001079ab610 llvm::LiveVariables::runOnMachineFunction(llvm::MachineFunction&) + 672
12 llc                      0x0000000107a2254e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 110
13 llc                      0x0000000107eec55b llvm::FPPassManager::runOnFunction(llvm::Function&) + 427
14 llc                      0x0000000107eec868 llvm::FPPassManager::runOnModule(llvm::Module&) + 104
15 llc                      0x0000000107eed274 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) + 1412
16 llc                      0x0000000107eecb1e llvm::legacy::PassManagerImpl::run(llvm::Module&) + 302
17 llc                      0x0000000107eed9f1 llvm::legacy::PassManager::run(llvm::Module&) + 33
18 llc                      0x00000001075c3e39 compileModule(char**, llvm::LLVMContext&) + 8441
19 llc                      0x00000001075c1cd9 main + 233
20 libdyld.dylib            0x00007fff8acda5c9 start + 1

Bad code generated with large stack frames

The following code snippet:

typedef float vecf16 __attribute__ ((vector_size(16 * sizeof(float))));
typedef struct matrix { vecf16 rows[16]; } matrix_t;

matrix_t genSpace()
{
    int i, j;
    matrix_t m_ret, m1, m1t;

...crashes on function entry, when it attempts to save a callee saved register in the new stack frame. Here is the objdump of the offending code:

     494:   84 04 80 07     move s4, 1
     498:   84 00 b6 c0     shl s4, s4, s12
     49c:   9d 00 52 c0     add_i s4, sp, s4
     4a0:   84 f3 01 88     store_32 fp, 124(s4)

s12 is never assigned a value in this function. It's zero when the simulator starts, so the offset is 1 byte, resulting in an unaligned access.

Building with -S outputs the following:

    move s4, 1
    shl s4, s4, 12
    add_i s4, sp, s4
    store_32 fp, 124(s4)            ; 4-byte Folded Spill

The instruction was supposed to be using the immediate value 12. It generated the wrong instruction type and treated that as register 12 instead.

Backend assert when function is too large

NyuziProcessor/tests/compiler/csmith1.c

testing csmith1.c at -O3 (simulator) FAIL: line 10 expected string checksum = 92ec5287 was not found
searching here:Load Access Violation 48b2364f, pc 00004588
REGISTERS
 r0 fddf1bad  r1 00000000  r2 006cd733  r3 00000000  r4 00000003  r5 00000000  r6 00008024  r7 00008008 
 r8 00000000  r9 00000000 r10 00000000 r11 00000000 r12 00000000 r13 00000000 r14 00000000 r15 00000000 
r16 00000000 r17 00000000 r18 00000000 r19 00000000 r20 00000000 r21 00000000 r22 00000000 r23 00000000 
r24 48b2364b r25 00000004 r26 00000009 r27 00000fff r28 00000000 r29 001fff80 r30 000000d0 r31 00004588

Assertion: Cannot select load

https://gist.github.com/jbush001/01ecb98b12f9509afb50
https://gist.github.com/jbush001/aee0192fea97463d6b6d

fatal error: error in backend: Cannot select: 0x7fea5b1586b8: i32,ch = load 0x7fea5b15eea0, 0x7fea5b152d78,
      0x7fea5a8fc990<LD1[@g_360], sext from i1> [ORD=4] [ID=39]
  0x7fea5b152d78: i32,ch = load 0x7fea5a58a5b0, 0x7fea5b152ea0, 0x7fea5a8fc990<LD4[ConstantPool]> [ORD=4] [ID=29]
    0x7fea5b152ea0: i32 = TargetConstantPool<@g_360 = internal unnamed_addr global i1 false> 0 [ID=21]
    0x7fea5a8fc990: i32 = undef [ID=11]
  0x7fea5a8fc990: i32 = undef [ID=11]
In function: main

mclinker: debug string table merged incorrectly

When attempting to list source code, lldb cannot find the file. It knows the correct line and filename.

* thread #1: tid = 0x0001, 0x00000494 doom.elf`clang version 3.6.0 (trunk) + 88 at i_video.c:157, stop reason = signal SIGTRAP
    frame #0: 0x00000494 doom.elf`clang version 3.6.0 (trunk) + 88 at i_video.c:157
(lldb) list
(lldb) list i_video.c:157
error: Could not find source file "i_video.c".

Test CodeGen/Generic/2009-11-16-BadKillsCrash.ll fails

Recent regression, possibly in upstream integration:

Assertion failed: (R == 0 && "Already initialized this value register!"), function InitializeRegForValue, file /Users/jeffbush/src/NyuziToolchain/include/llvm/CodeGen/FunctionLoweringInfo.h, line 169.
0  llc                      0x000000010181f89e llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 46
1  llc                      0x0000000101820e69 PrintStackTraceSignalHandler(void*) + 25
2  llc                      0x00000001018212be SignalHandler(int) + 590
3  libsystem_platform.dylib 0x00007fff97510f1a _sigtramp + 26
4  llc                      0x0000000101aee8ce (anonymous namespace)::RewriteSymbols::ID + 35778
5  llc                      0x0000000101820e8b raise + 27
6  llc                      0x0000000101820f42 abort + 18
7  llc                      0x0000000101820f21 __assert_rtn + 129
8  llc                      0x00000001016880e9 llvm::FunctionLoweringInfo::InitializeRegForValue(llvm::Value const*) + 137
9  llc                      0x00000001016459a3 llvm::SelectionDAGBuilder::getValueImpl(llvm::Value const*) + 5699
10 llc                      0x0000000101645ccc llvm::SelectionDAGBuilder::getNonRegisterValue(llvm::Value const*) + 108
11 llc                      0x0000000101645d8a llvm::SelectionDAGBuilder::CopyValueToVirtualRegister(llvm::Value const*, unsigned int) + 74
12 llc                      0x0000000101634db9 llvm::SelectionDAGBuilder::CopyToExportRegsIfNeeded(llvm::Value const*) + 297
13 llc                      0x0000000101633c4d llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) + 189
14 llc                      0x00000001016b6e5c llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::Instruction const>, llvm::ilist_iterator<llvm::Instruction const>, bool&) + 140
15 llc                      0x00000001016b6be7 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 5207
16 llc                      0x00000001016b43bb llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1147
17 llc                      0x0000000100d4d54e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 110
18 llc                      0x000000010121755b llvm::FPPassManager::runOnFunction(llvm::Function&) + 427
19 llc                      0x0000000101217868 llvm::FPPassManager::runOnModule(llvm::Module&) + 104
20 llc                      0x0000000101218274 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) + 1412
21 llc                      0x0000000101217b1e llvm::legacy::PassManagerImpl::run(llvm::Module&) + 302
22 llc                      0x00000001012189f1 llvm::legacy::PassManager::run(llvm::Module&) + 33
23 llc                      0x00000001008eee39 compileModule(char**, llvm::LLVMContext&) + 8441
24 llc                      0x00000001008eccd9 main + 233
25 libdyld.dylib            0x00007fff8acda5c9 start + 1

MCLinker crashes when using linker script

* thread #1: tid = 0x24adb3, 0x00007fff9172b866 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff9172b866 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff91dae35c libsystem_pthread.dylib`pthread_kill + 92
    frame #2: 0x00007fff8a189bba libsystem_c.dylib`__abort + 145
    frame #3: 0x00007fff8a18a46d libsystem_c.dylib`__stack_chk_fail + 196
    frame #4: 0x00000001000c22d4 ld.mcld`mcld::ScriptReader::readScript(mcld::LinkerConfig const&, mcld::ScriptFile&) + 1204
    frame #5: 0x00000001000891c5 ld.mcld`mcld::ObjectLinker::normalize(this=0x0000000100504c40) + 4565 at ObjectLinker.cpp:214
    frame #6: 0x00000001000480fc ld.mcld`mcld::Linker::normalize(this=0x00007fff5fbff588, pModule=0x00007fff5fbff6e0, pBuilder=0x00007fff5fbff5d0) + 300 at Linker.cpp:104
    frame #7: 0x0000000100047f77 ld.mcld`mcld::Linker::link(this=0x00007fff5fbff588, pModule=0x00007fff5fbff6e0, pBuilder=0x00007fff5fbff5d0) + 55 at Linker.cpp:67
    frame #8: 0x0000000100001c70 ld.mcld`main(argc=5, argv=0x00007fff5fbffb30) + 752 at main.cpp:151
    frame #9: 0x00007fff875555fd libdyld.dylib`start + 1

Assertion failed: (Op && "Cannot dereference end iterator!")

Assertion failed: (Op && "Cannot dereference end iterator!"), function getOperandNo, file /Users/jeffbush/src/NyuziToolchain/include/llvm/CodeGen/MachineRegisterInfo.h, line 871.
0  clang-3.6                0x000000010202baee llvm::sys::PrintStackTrace(__sFILE*) + 46
1  clang-3.6                0x000000010202ce9b PrintStackTraceSignalHandler(void*) + 27
2  clang-3.6                0x000000010202d2e5 SignalHandler(int) + 565
3  libsystem_platform.dylib 0x00007fff80a945aa _sigtramp + 26
4  libsystem_platform.dylib 0x00007fce0320f2c0 _sigtramp + 2188881200
5  clang-3.6                0x000000010202cecb raise + 27
6  clang-3.6                0x000000010202cf82 abort + 18
7  clang-3.6                0x000000010202cf61 __assert_rtn + 129
8  clang-3.6                0x0000000101712fe8 llvm::MachineRegisterInfo::defusechain_iterator<false, true, false, true, false, false>::getOperandNo() const + 104
9  clang-3.6                0x000000010170f2a0 (anonymous namespace)::ValueTracker::getNextSource(unsigned int&, unsigned int&) + 176
10 clang-3.6                0x000000010170f0d4 (anonymous namespace)::PeepholeOptimizer::findNextSource(unsigned int&, unsigned int&) + 244
11 clang-3.6                0x000000010170dcc8 (anonymous namespace)::PeepholeOptimizer::optimizeCoalescableCopy(llvm::MachineInstr*) + 808
12 clang-3.6                0x000000010170c9d4 (anonymous namespace)::PeepholeOptimizer::runOnMachineFunction(llvm::MachineFunction&) + 1508
13 clang-3.6                0x0000000101640e2e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 110
14 clang-3.6                0x00000001019fb98b llvm::FPPassManager::runOnFunction(llvm::Function&) + 427
15 clang-3.6                0x00000001019fbc98 llvm::FPPassManager::runOnModule(llvm::Module&) + 104
16 clang-3.6                0x00000001019fc6a4 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) + 1412
17 clang-3.6                0x00000001019fbf4e llvm::legacy::PassManagerImpl::run(llvm::Module&) + 302
18 clang-3.6                0x00000001019fce21 llvm::legacy::PassManager::run(llvm::Module&) + 33
19 clang-3.6                0x0000000102870361 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, llvm::raw_ostream*) + 1601
20 clang-3.6                0x000000010286fb12 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 114
21 clang-3.6                0x0000000102a86cd5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1397
22 clang-3.6                0x00000001035817f4 clang::ParseAST(clang::Sema&, bool, bool) + 1268
23 clang-3.6                0x000000010248f87a clang::ASTFrontendAction::ExecuteAction() + 522
24 clang-3.6                0x0000000102a84d93 clang::CodeGenAction::ExecuteAction() + 3939
25 clang-3.6                0x000000010248edf8 clang::FrontendAction::Execute() + 120
26 clang-3.6                0x0000000102420779 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1017
27 clang-3.6                0x0000000102500f01 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3201
28 clang-3.6                0x0000000101244d00 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2496
29 clang-3.6                0x000000010123721b ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) + 171
30 clang-3.6                0x000000010123608a main + 1274
31 libdyld.dylib            0x00007fff825ca5fd start + 1
32 libdyld.dylib            0x000000000000002f start + 2107857459
Stack dump:
0.  Program arguments: /usr/local/llvm-nyuzi/bin/clang-3.6 -cc1 -triple nyuzi-none-none -emit-obj -disable-free -main-file-name viewobj.cpp -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -nostdsysteminc -fuse-init-array -target-linker-version 241.8 -momit-leaf-frame-pointer -g -dwarf-column-info -D FB_WIDTH=800 -D FB_HEIGHT=600 -O3 -Wall -W -std=c++11 -fdeprecated-macro -ferror-limit 19 -fmessage-length 106 -mstackrealign -fno-rtti -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -x c++ viewobj-da6881.cpp 

Preprocessed source code:

https://gist.github.com/jbush001/dad09925e33afaee24ae

Useless branches generated

Seeing lots of branches between adjacent basic blocks:

     630:   00 16 00 f4                                     btrue s0, 176
     634:   00 00 00 f6                                     goto 0
     638:   00 00 80 07                                     move s0, 0

...in generated code. It looks like NyuziInstrInfo::AnalyzeBranch may have broken.

Assembler asserts when undefined symbol is referenced by LEA

The following program:

_start:     lea s1, blargh

Should display an error that blargh is undefined. Instead, it hits an ugly assertion:

Invalid fixup kind!
UNREACHABLE executed at /Users/jeffbush/src/NyuziToolchain/lib/Target/Nyuzi/MCTargetDesc/NyuziELFObjectWriter.cpp:45!

The issue is in the code below. This should handle this error more gracefully.

unsigned NyuziELFObjectWriter::GetRelocType(const MCValue &Target,
                                                 const MCFixup &Fixup,
                                                 bool IsPCRel) const {
  unsigned Type;
  unsigned Kind = (unsigned)Fixup.getKind();
  switch (Kind) {
  default:
    llvm_unreachable("Invalid fixup kind!");

Fixed point version of FixedMul in Doom doesn't work

This is the default version of FixedMul in NyuziProcessor/software/doom/m_fixed.c:

fixed_t FixedMul( fixed_t a, fixed_t b )
{
    return ((long long) a * (long long) b) >> FRACBITS;
}

This returns incorrect results, causing a garbled screen. If I perform the operation in floating point, it works correctly:

fixed_t FixedMul (fixed_t a, fixed_t b)
{
    return ((float) a * (float) b) / FRACUNIT;
}

mclinker does not have proper dependencies for script parser/lexer

This is a problem in the upstream project. It always regenerates the parser/lexer:

Scanning dependencies of target MCLDScript

[ 95%] Building CXX object tools/mclinker/lib/Script/CMakeFiles/MCLDScript.dir/ScriptReader.cpp.o
[ 95%] [BISON][PARSER] Building parser with bison 3.0.4
...
[ 95%] Building CXX object tools/mclinker/lib/Script/CMakeFiles/MCLDScript.dir/ScriptParser.cpp.o

When doing sudo make install, this creates files with root ownership in the build directory, which causes subsequent non-sudo builds to fail with permission problems.

Clang is eating trailing newlines in constant strings

int main(int argc, const char *argv[]) {
    printf("foo\n");
}

The constant string compiles to:

.Lstr:
    .asciz  "foo"
    .size   .Lstr, 4

This seems to be happening in the front end of the compiler, as even the IR is missing them:

@str = private unnamed_addr constant [4 x i8] c"foo\00"

If two newlines are added, the last gets stripped:

    printf("foo\n\n");

Outputs:

.Lstr:
    .asciz  "foo\n"
    .size   .Lstr, 5

This only happens at -O3. At the default optimization level, the newlines are intact.

Vector cmp/mix intrinsics inhibit optimizations

For example, this C function (chosen for simplicity, not because it's code I would want to write) simply returns its first argument times two, if we ignore NaN for a second:

vecf16_t double(vecf16_t a, vecf16_t b) {
	return __builtin_nyuzi_vector_mixf(__builtin_nyuzi_mask_cmpf_eq(a, a), a + a, b);
}

When compiled with clang -O -ffast-math, it results in IR like this, which is correct but not very optimized:

; Function Attrs: nounwind readnone uwtable
define <16 x float> @double(<16 x float> %a, <16 x float> %b) local_unnamed_addr #0 {
entry:
  %0 = tail call i32 @llvm.nyuzi.__builtin_nyuzi_mask_cmpf_eq(<16 x float> %a, <16 x float> %a)
  %factor = fmul fast <16 x float> %a, <float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00>
  %1 = tail call fast <16 x float> @llvm.nyuzi.__builtin_nyuzi_vector_mixf(i32 %0, <16 x float> %factor, <16 x float> %b)
  ret <16 x float> %1
}

So, the comparison did not get optimized into a constant and subsequently the mix did not get optimized out either. By the way, hard-coding the mask (i.e., replacing the first argument with i32 0 or something) does not optimize the mix either.

I conclude that both families of intrinsics are almost entirely opaque to the optimizer. (The TableGen files do indicate that they don't access memory. This does allow optimization of surrounding code but doesn't help with optimizing the intrinsics themselves.)


Okay, what if I am not writing C code, but instead generating LLVM IR from an alternative frontend? I hoped that LLVM's first-class vector operations could help, so I wrote this IR by hand:

define <16 x float> @double(<16 x float> %a, <16 x float> %b) local_unnamed_addr #0 {
entry:
  %0 = fcmp fast ueq <16 x float> %a, %a ; NaN-ignoring comparison
  %add = fadd fast <16 x float> %a, %a
  %1 = select <16 x i1> %0, <16 x float> %add, <16 x float> %b
  ret <16 x float> %1
}

The above indeed gets optimized to a simple return a + a;, but that's only because the select is optimized out entirely before the backend is involved. Code that actually needs a vector-typed select (e.g., changing the comparison to fcmp ogt <16 x float> %a, %b) crashes in ISel with messages like LLVM ERROR: Cannot select: t12: v16f32 = vselect t26, t11, t4. As a point of comparison, the x86 backend happily accepts such code, even if it has to emulate 16-wide vectors and blends within the limits of SSE 2 (and it does quite a good job!).


The question, then, is how to fix this issue. To be clear, I am not asking you, @jbush001, to fix this. I hopefully can do that on my own. But I do have some questions, which mostly boil down to: Why do these intrinsics exist at all? Is it just that they predate the addition of vector-typed comparisons and select instructions to LLVM? Or is there a deeper reason, a semantic difference perhaps?

If it's just a matter of history, I would try to eliminate these intrinsics from the Nyuzi backend, change Clang to lower these __builtin_* functions to first-class IR instructions, and change the backend to match on these instructions (resp. their SelectionDAG equivalent) rather than the intrinsics. Does that sound like a plan?

Compilation error. Missing histedit.h

[ 62%] Building CXX object tools/lldb/source/Core/CMakeFiles/lldbCore.dir/IOHandler.cpp.o
In file included from /home/olof/code/or1k/staging/NyuziToolchain/tools/lldb/source/Core/IOHandler.cpp:32:0:
/home/olof/code/or1k/staging/NyuziToolchain/tools/lldb/include/lldb/Host/Editline.h:48:22: fatal error: histedit.h: No such file or directory
#include <histedit.h>
^
compilation terminated.
tools/lldb/source/Core/CMakeFiles/lldbCore.dir/build.make:721: recipe for target 'tools/lldb/source/Core/CMakeFiles/lldbCore.dir/IOHandler.cpp.o' failed
make[2]: *** [tools/lldb/source/Core/CMakeFiles/lldbCore.dir/IOHandler.cpp.o] Error 1
CMakeFiles/Makefile2:11211: recipe for target 'tools/lldb/source/Core/CMakeFiles/lldbCore.dir/all' failed
make[1]: *** [tools/lldb/source/Core/CMakeFiles/lldbCore.dir/all] Error 2
Makefile:136: recipe for target 'all' failed
make: *** [all] Error 2

SLP vectorizer causes backend assert

The following code:

void simple_crypt(char *buf, int len)
{
    while (len--)
        *buf++ ^= 0xff;
}

char prespawn_name[] = 
    { 'p'^0xff, 'r'^0xff, 'e'^0xff, 's'^0xff, 'p'^0xff, 'a'^0xff, 'w'^0xff, 'n'^0xff,
        ' '^0xff, '%'^0xff, 'i'^0xff, ' '^0xff, '0'^0xff, ' '^0xff, '%'^0xff, 'i'^0xff, 0 };

int main()
{
    simple_crypt(prespawn_name,  sizeof(prespawn_name)  - 1);
}

Causes an assert:

$/usr/local/llvm-nyuzi/bin/clang -O3 -c error.c 

fatal error: error in backend: Cannot select: 0x7f99db0be7b0: ch = store 0x7f99db0c3770:1, 0x7f99db0be8c0,
      0x7f99db0c0b70, 0x7f99db0c3330<ST16[bitcast ([17 x i8]* @prespawn_name to <16 x i8>*)](tbaa=metadata <badref>),
      trunc to v16i8> [ORD=4] [ID=10]
  0x7f99db0be8c0: v16i32 = xor 0x7f99db0c3770, 0x7f99db0c0840 [ORD=3] [ID=9]
    0x7f99db0c3770: v16i32,ch = load 0x7f99dad23a90, 0x7f99db0c0b70, 0x7f99db0c3330<LD16[bitcast ([17 x i8]* @prespawn_name to <16 x i8>*)](tbaa=metadata <badref>), anyext from v16i8> [ORD=2] [ID=8]
      0x7f99db0c0b70: i32,ch = load 0x7f99dad23a90, 0x7f99db0c1c80, 0x7f99db0c3330<LD4[ConstantPool]> [ORD=2] [ID=7]
        0x7f99db0c1c80: i32 = TargetConstantPool<@prespawn_name = global [17 x i8] c"\8F\8D\9A\8C\8F\9E\88\91\DF\DA\96\DF\CF\DF\DA\96\00", align 16> 0 [ID=5]
        0x7f99db0c3330: i32 = undef [ID=2]
      0x7f99db0c3330: i32 = undef [ID=2]
    0x7f99db0c0840: v16i32 = NyuziISD::SPLAT 0x7f99db0c0d90 [ORD=3] [ID=6]
      0x7f99db0c0d90: i32 = Constant<255> [ID=4]
  0x7f99db0c0b70: i32,ch = load 0x7f99dad23a90, 0x7f99db0c1c80, 0x7f99db0c3330<LD4[ConstantPool]> [ORD=2] [ID=7]
    0x7f99db0c1c80: i32 = TargetConstantPool<@prespawn_name = global [17 x i8] c"\8F\8D\9A\8C\8F\9E\88\91\DF\DA\96\DF\CF\DF\DA\96\00", align 16> 0 [ID=5]
    0x7f99db0c3330: i32 = undef [ID=2]
  0x7f99db0c3330: i32 = undef [ID=2]

The problem is that it has created a store for a non-supported vector type [16 x i8].

Adding -fno-slp-vectorize works around the problem.

Assertion failed (cannot select setcc) while compiling lua

/usr/local/llvm-nyuzi/bin/clang -O2 -Wall -DLUA_COMPAT_ALL   -I../../libc/include   -c -o ltable.o ltable.c
fatal error: error in backend: Cannot select: 0x7f80210b7000: i32 = setcc 0x7f80210b8c20,
      0x7f80210b8c20, 0x7f80228a4938 [ORD=4] [ID=8]
  0x7f80210b8c20: f32,ch = load 0x7f8020f95f50, 0x7f80210b7630, 0x7f80228a4c50<LD4[%n](tbaa=<badref>)> [ORD=3] [ID=7]
    0x7f80210b7630: i32,ch = CopyFromReg 0x7f8020f95f50, 0x7f80228a4410 [ORD=2] [ID=6]
      0x7f80228a4410: i32 = Register %vreg65 [ID=1]
    0x7f80228a4c50: i32 = undef [ID=2]
  0x7f80210b8c20: f32,ch = load 0x7f8020f95f50, 0x7f80210b7630, 0x7f80228a4c50<LD4[%n](tbaa=<badref>)> [ORD=3] [ID=7]
    0x7f80210b7630: i32,ch = CopyFromReg 0x7f8020f95f50, 0x7f80228a4410 [ORD=2] [ID=6]
      0x7f80228a4410: i32 = Register %vreg65 [ID=1]
    0x7f80228a4c50: i32 = undef [ID=2]
In function: luaH_newkey

Build command:

 "/usr/local/llvm-nyuzi/bin/clang-3.6" -cc1 -triple nyuzi- -emit-obj -disable-free -main-file-name ltable.c -mrelocation-model static -fmath-errno -masm-verbose -mconstructor-aliases -nostdsysteminc -fuse-init-array -momit-leaf-frame-pointer -dwarf-column-info -D "LUA_COMPAT_ALL" -O2 -Wall -ferror-limit 19 -fmessage-length 104 -mstackrealign -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -x c ltable-25a254.c

Preprocessed source:

https://gist.github.com/jbush001/3facc41447f9520d9b5c

Inlined function with tail call generates unreachable

The following source generates bad code:

static int function1() {
    printf("B\n");
}

void function2() {
    function1();
    printf("C\n");
}

int main(int argc, const char *argv[]) {
    function2();
}

At -O0, the compiler inserts an 'unreachable' instrution after printf, even though printf is not a tail call. This causes a trap:

define i32 @_Z9function1v() #0 {
entry:
  %retval = alloca i32, align 4
  %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0))
  call void @llvm.trap()
  unreachable
return:                                           ; No predecessors!
  %0 = load i32, i32* %retval
  ret i32 %0
}

At -O3, function 1 is inlined inside function 2. It drops the last printf ("C") and runs off the end of the function, which now has no epilogue:

@str.2 = private unnamed_addr constant [2 x i8] c"B\00"
define void @_Z9function2v() #0 {
entry:
  %puts.i = tail call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str.2, i32 0, i32 0)) #1
  unreachable
}

The assembly looks like this:

_Z9function2v: 
    add_i sp, sp, -64
    store_32 ra, 60(sp)             ; 4-byte Folded Spill
    load_32 s0, .LCPI0_0
    call puts
.Lfunc_end0:
    .size   _Z9function2v, .Lfunc_end0-_Z9function2v
    .cfi_endproc

    .globl  main

Changing the return type of function1 to void fixes the problem, as does adding a 'return 0' at the end.

Assertion failed: (BestRC && "Couldn't find the register class")

Assertion failed: (BestRC && "Couldn't find the register class"), function getMinimalPhysRegClass, file /Users/jeffbush/src/NyuziToolchain/lib/CodeGen/TargetRegisterInfo.cpp, line 124.
0  clang-3.6                0x000000010fcbfdfe llvm::sys::PrintStackTrace(__sFILE*) + 46
1  clang-3.6                0x000000010fcc010b PrintStackTraceSignalHandler(void*) + 27
2  clang-3.6                0x000000010fcc0535 SignalHandler(int) + 565
3  libsystem_platform.dylib 0x00007fff8290d5aa _sigtramp + 26
4  libsystem_malloc.dylib   0x00007fff8796805a szone_free_definite_size + 1672
5  clang-3.6                0x000000010fcc013b raise + 27
6  clang-3.6                0x000000010fcc01f2 abort + 18
7  clang-3.6                0x000000010fcc01d1 __assert_rtn + 129
8  clang-3.6                0x000000010f4e0495 llvm::TargetRegisterInfo::getMinimalPhysRegClass(unsigned int, llvm::EVT) const + 453
9  clang-3.6                0x00000001103801c6 (anonymous namespace)::ScheduleDAGRRList::PickNodeToScheduleBottomUp() + 2534
10 clang-3.6                0x000000011037edea (anonymous namespace)::ScheduleDAGRRList::ListScheduleBottomUp() + 714
11 clang-3.6                0x000000011037ea75 (anonymous namespace)::ScheduleDAGRRList::Schedule() + 885
12 clang-3.6                0x000000011038a8c9 llvm::ScheduleDAGSDNodes::Run(llvm::SelectionDAG*, llvm::MachineBasicBlock*) + 313
13 clang-3.6                0x000000011046fd79 llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 6201
14 clang-3.6                0x000000011046e52d llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::Instruction const>, llvm::ilist_iterator<llvm::Instruction const>, bool&) + 253
15 clang-3.6                0x000000011046e24b llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 5227
16 clang-3.6                0x000000011046bb75 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1205
17 clang-3.6                0x000000010f31f53e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 110
18 clang-3.6                0x000000010f6c8f7b llvm::FPPassManager::runOnFunction(llvm::Function&) + 427
19 clang-3.6                0x000000010f6c9288 llvm::FPPassManager::runOnModule(llvm::Module&) + 104
20 clang-3.6                0x000000010f6c9c94 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) + 1412
21 clang-3.6                0x000000010f6c953e llvm::legacy::PassManagerImpl::run(llvm::Module&) + 302
22 clang-3.6                0x000000010f6ca411 llvm::legacy::PassManager::run(llvm::Module&) + 33
23 clang-3.6                0x00000001104bd801 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, llvm::raw_ostream*) + 1601
24 clang-3.6                0x00000001104bcfb2 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 114
25 clang-3.6                0x00000001106b1103 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1731
26 clang-3.6                0x0000000111163b64 clang::ParseAST(clang::Sema&, bool, bool) + 1268
27 clang-3.6                0x00000001100fdd9a clang::ASTFrontendAction::ExecuteAction() + 522
28 clang-3.6                0x00000001106af073 clang::CodeGenAction::ExecuteAction() + 3939
29 clang-3.6                0x00000001100fd318 clang::FrontendAction::Execute() + 120
30 clang-3.6                0x0000000110090d09 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1017
31 clang-3.6                0x0000000110167751 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3201
32 clang-3.6                0x000000010ef40a90 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2496
33 clang-3.6                0x000000010ef349bb ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) + 171
34 clang-3.6                0x000000010ef33f71 main + 1185
35 libdyld.dylib            0x00007fff844435fd start + 1
36 libdyld.dylib            0x0000000000000027 start + 2075904555
Stack dump:
0.  Program arguments: /usr/local/llvm-nyuzi/bin/clang-3.6 -cc1 -triple nyuzi- -emit-obj -disable-free -main-file-name meteor-contest.c -mrelocation-model static -fmath-errno -masm-verbose -mconstructor-aliases -nostdsysteminc -fuse-init-array -momit-leaf-frame-pointer -dwarf-column-info -resource-dir /usr/local/llvm-nyuzi/bin/../lib/clang/3.6.0 -I ../../software/libc/include -O3 -fdebug-compilation-dir /Users/jeffbush/src/NyuziProcessor/tests/meteor-contest -ferror-limit 19 -fmessage-length 115 -mstackrealign -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /var/folders/my/3z_wh8qj6j5gvrn621k1xlph0000gn/T/meteor-contest-111564.o -x c meteor-contest.c 

Code is here:

https://gist.github.com/jbush001/2277233ea15b22c8de31

Clang crash with undefined variables

The following

static void foo()
{
    bar(a, (b + 1));
}

Crashes:

Assertion failed: (Entry != DelayedTypos.end() && "Failed to get the state for a TypoExpr!"), function getTypoExprState, file /Users/jeffbush/src/NyuziToolchain/tools/clang/lib/Sema/SemaLookup.cpp, line 5032.
0  clang-3.9                0x000000010a6207ae llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 46
1  clang-3.9                0x000000010a620c09 PrintStackTraceSignalHandler(void*) + 25
2  clang-3.9                0x000000010a61d719 llvm::sys::RunSignalHandlers() + 425
3  clang-3.9                0x000000010a620f94 SignalHandler(int) + 372
4  libsystem_platform.dylib 0x00007fff937aef1a _sigtramp + 26
5  clang-3.9                0x000000010df4d8ac guard variable for shouldAddRequirement(clang::Module*, llvm::StringRef, bool&)::IOKitAVC + 81916
6  clang-3.9                0x000000010a620c2b raise + 27
7  clang-3.9                0x000000010a620ce2 abort + 18
8  clang-3.9                0x000000010a620cc1 __assert_rtn + 129
9  clang-3.9                0x000000010cb57c81 clang::Sema::getTypoExprState(clang::TypoExpr*) const + 225
10 clang-3.9                0x000000010ca9881c (anonymous namespace)::TransformTypos::TransformTypoExpr(clang::TypoExpr*) + 188
11 clang-3.9                0x000000010ca89c5a clang::TreeTransform<(anonymous namespace)::TransformTypos>::TransformExpr(clang::Expr*) + 5114
12 clang-3.9                0x000000010ca42ae7 (anonymous namespace)::TransformTypos::TryTransform(clang::Expr*) + 71
13 clang-3.9                0x000000010ca418c1 (anonymous namespace)::TransformTypos::Transform(clang::Expr*) + 65
14 clang-3.9                0x000000010ca4169d clang::Sema::CorrectDelayedTyposInExpr(clang::Expr*, clang::VarDecl*, llvm::function_ref<clang::ActionResult<clang::Expr*, true> (clang::Expr*)>) + 493
15 clang-3.9                0x000000010c9f3eca clang::Sema::CorrectDelayedTyposInExpr(clang::Expr*, llvm::function_ref<clang::ActionResult<clang::Expr*, true> (clang::Expr*)>) + 74
16 clang-3.9                0x000000010c9f6947 clang::Sema::CorrectDelayedTyposInExpr(clang::ActionResult<clang::Expr*, true>, clang::VarDecl*, llvm::function_ref<clang::ActionResult<clang::Expr*, true> (clang::Expr*)>) + 119
17 clang-3.9                0x000000010c1fe4cb clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr*, true>, clang::prec::Level) + 6107
18 clang-3.9                0x000000010c1fccd8 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 280
19 clang-3.9                0x000000010c1fcb8f clang::Parser::ParseExpression(clang::Parser::TypeCastState) + 31
20 clang-3.9                0x000000010c206f41 clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, bool, bool, clang::OpaquePtr<clang::QualType>&, clang::SourceLocation&) + 5729
21 clang-3.9                0x000000010c200d71 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState) + 401
22 clang-3.9                0x000000010c1fe773 clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState) + 83
23 clang-3.9                0x000000010c1fccba clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 250
24 clang-3.9                0x000000010c20a933 clang::Parser::ParseExpressionList(llvm::SmallVectorImpl<clang::Expr*>&, llvm::SmallVectorImpl<clang::SourceLocation>&, std::__1::function<void ()>) + 371
25 clang-3.9                0x000000010c1ff917 clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) + 4263
26 clang-3.9                0x000000010c205278 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState) + 18072
27 clang-3.9                0x000000010c1fe773 clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState) + 83
28 clang-3.9                0x000000010c1fccba clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 250
29 clang-3.9                0x000000010c1fcb8f clang::Parser::ParseExpression(clang::Parser::TypeCastState) + 31
30 clang-3.9                0x000000010c25ec7c clang::Parser::ParseExprStatement() + 60
31 clang-3.9                0x000000010c25dbff clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::AllowedContsructsKind, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) + 2751
32 clang-3.9                0x000000010c25cff8 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::AllowedContsructsKind, clang::SourceLocation*) + 168
33 clang-3.9                0x000000010c264b1a clang::Parser::ParseCompoundStatementBody(bool) + 1322
34 clang-3.9                0x000000010c265740 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) + 496
35 clang-3.9                0x000000010c286462 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) + 3922
36 clang-3.9                0x000000010c1bbdf5 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 1061
37 clang-3.9                0x000000010c2854d5 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) + 1397
38 clang-3.9                0x000000010c284b65 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) + 197
39 clang-3.9                0x000000010c2842ed clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 3981
40 clang-3.9                0x000000010c283315 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 1061
41 clang-3.9                0x000000010c1a24ee clang::ParseAST(clang::Sema&, bool, bool) + 766
42 clang-3.9                0x000000010b1d548f clang::ASTFrontendAction::ExecuteAction() + 511
43 clang-3.9                0x000000010ac34bcb clang::CodeGenAction::ExecuteAction() + 6043
44 clang-3.9                0x000000010b1d49b8 clang::FrontendAction::Execute() + 120
45 clang-3.9                0x000000010b117bc7 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1847
46 clang-3.9                0x000000010b268466 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 4870
47 clang-3.9                0x000000010944164a cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 4986
48 clang-3.9                0x0000000109431011 ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) + 481
49 clang-3.9                0x000000010942eb23 main + 3283
50 libdyld.dylib            0x00007fff86f785c9 start + 1
51 libdyld.dylib            0x0000000000000024 start + 2030598748
Stack dump:
0.  Program arguments: /usr/local/llvm-nyuzi/bin/clang-3.9 -cc1 -triple nyuzi-none-none -emit-obj -disable-free -main-file-name thread.c -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -nostdsysteminc -fuse-init-array -target-cpu nyuzi -target-linker-version 241.9 -momit-leaf-frame-pointer -dwarf-column-info -debugger-tuning=gdb -O3 -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -x c thread-8755e8.c 
1.  thread-8755e8.c:6:18: current parser token ')'
2.  thread-8755e8.c:5:1: parsing function body 'foo'
3.  thread-8755e8.c:5:1: in compound statement ('{}')
./thread-8755e8.sh: line 4: 88650 Illegal instruction: 4  "/usr/local/llvm-nyuzi/bin/clang-3.9" "-cc1" "-triple" "nyuzi-none-none" "-emit-obj" "-disable-free" "-main-file-name" "thread.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-nostdsysteminc" "-fuse-init-array" "-target-cpu" "nyuzi" "-target-linker-version" "241.9" "-momit-leaf-frame-pointer" "-dwarf-column-info" "-debugger-tuning=gdb" "-O3" "-ferror-limit" "19" "-fmessage-length" "80" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-x" "c" "thread-8755e8.c"

This may be a bug that was pulled in from the last upstream integration. Retest with next one.

sextload1 generates bad code

Fix for ca6a75b introduced a new problem. The following C code:

static unsigned int foo;
void setvar() { foo = 0xffffffff; }
int getvar() { return foo; }

Generates LLVM:

@foo = internal unnamed_addr global i1 false, align 4

define void @setvar() local_unnamed_addr #0 {
entry:
  store i1 true, i1* @foo, align 4
  ret void
}

define i32 @getvar() local_unnamed_addr #1 {
entry:
  %.b = load i1, i1* @foo, align 4
  %0 = sext i1 %.b to i32
  ret i32 %0
}

Note that it has converted @foo to i1 and is relying on sext to convert it back to 0xffffffff. The backend matches sextload1 and converts it to a 8 bit signed extension, which results in bad code for getvar:

getvar:
    load_32 s0, .LCPI1_0
    load_s8 s0, (s0)
    ret

The load_s8 doesn't extend the low bit, resulting in it returning 1 instead of 0xffffffff

assertion: Cannot select i32,ch = load<LD1[@_ZL8fg_color](align=4), sext from i1>

fatal error: error in backend: Cannot select: 0x7fa8c4017c30: i32,ch = load<LD1[@_ZL8fg_color](align=4), sext from i1> 0x7fa8c241b630,
      0x7fa8c3870650, undef:i32
  0x7fa8c3870650: i32,ch = load<LD4[ConstantPool]> 0x7fa8c241b630, TargetConstantPool:i32<@_ZL8fg_color = internal unnamed_addr global i1 false, align 4> 0, undef:i32
    0x7fa8c3870030: i32 = TargetConstantPool<@_ZL8fg_color = internal unnamed_addr global i1 false, align 4> 0
    0x7fa8c38703b0: i32 = undef
  0x7fa8c38703b0: i32 = undef
In function: draw_glyph
clang-3.9: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 4.0.0 (trunk)
Target: nyuzi-none-none

Archive.zip

FAIL: LLVM :: CodeGen/Generic/fwdtwice.ll

Fails only on Mac (built with clang). Seems to be caused by most recent upstream integration, which had big ilist refactor. Retry with newer version.

FAIL: LLVM :: CodeGen/Generic/fwdtwice.ll (1 of 1)
Assertion failed: (!NodePtr->isKnownSentinel()), function operator*, file /Users/jeffbush/src/NyuziToolchain/include/llvm/ADT/ilist_iterator.h, line 126.

lldb: Current function name is incorrect

Note that the function is listed as "doom.elf`clang version 3.6.0 (trunk)" instead of the correct name.

Process 1 stopped
* thread #1: tid = 0x0001, 0x00000494 doom.elf`clang version 3.6.0 (trunk) + 88 at i_video.c:157, stop reason = signal SIGTRAP
    frame #0: 0x00000494 doom.elf`clang version 3.6.0 (trunk) + 88 at i_video.c:157

I believe this broke when the latest upstream was merged (commit 2b2e242).

Checking for NaN generates bad code

The following C code will always return 0:

int isnan(float a) {
    return !(a==a);
}

LLVM IR is:

define i32 @isnan(float %a) #0 {
entry:
  %lnot = fcmp uno float %a, 0.000000e+00
  %lnot.ext = zext i1 %lnot to i32
  ret i32 %lnot.ext
}

The generated code is:

isnan:
; BB#0:                                 ; %entry
    move s0, 0
    ret

However, using the ord comparison type:

%lnot = fcmp ord float %a, 0.000000e+00

Works correctly:

cmpeq_f s0, s0, s0
and s0, s0, 1
ret

There is a test for this (currently commented out) in test/CodeGen/Nyuzi/scalar_compare.ll

LLVM ERROR: Cannot select: t7: v16i32,ch = load<LD32[undef], anyext from v16i16>

The following program:

target triple = "nyuzi-none-none"

define void @autogen_SD5494() {
BB:
  %L17 = load <16 x i16>, <16 x i16>* undef
  br label %CF829

CF829:                                            ; preds = %CF829, %BB
  br i1 undef, label %CF829, label %CF851

CF851:                                            ; preds = %CF829
  br label %CF927

CF927:                                            ; preds = %CF927, %CF851
  %FC57 = uitofp <16 x i16> %L17 to <16 x double>
  br label %CF927
}

Causes an assertion:

LLVM ERROR: Cannot select: t7: v16i32,ch = load<LD32[undef], anyext from v16i16> t0, undef:i32, undef:i32
  t1: i32 = undef
  t1: i32 = undef

LLVM ERROR: Cannot select: store<ST16[%A3], trunc to v16i8>

The following program:

target triple = "nyuzi-none-none"

define void @autogen_SD31336() {
BB:
  br label %CF858

CF858:                                            ; preds = %CF858, %BB
  br i1 undef, label %CF858, label %CF864

CF864:                                            ; preds = %CF864, %CF858
  store <16 x i8> <i8 -1, i8 0, i8 -1, i8 0, i8 -1, i8 0, i8 -1, i8 0, i8 -1, i8 0, i8 -1, i8 0, i8 -1, i8 0, i8 -1, i8 0>, <16 x i8>* undef
  br label %CF864
}

Causes an assertion:

LLVM ERROR: Cannot select: t13: ch = store<ST16[undef], trunc to v16i8> t0, t15, undef:i32, undef:i32
  t15: v16i32,ch = load<LD64[ConstantPool]> t0, TargetConstantPool:i32<<16 x i32> <i32 255, i32 0, i32 255, i32 0, i32 255, i32 0, i32 255, i32 0, i32 255, i32 0, i32 255, i32 0, i32 255, i32 0, i32 255, i32 0>> 0, undef:i32
    t16: i32 = TargetConstantPool<<16 x i32> <i32 255, i32 0, i32 255, i32 0, i32 255, i32 0, i32 255, i32 0, i32 255, i32 0, i32 255, i32 0, i32 255, i32 0, i32 255, i32 0>> 0
    t4: i32 = undef
  t4: i32 = undef
  t4: i32 = undef

Vararg functions don't work correctly without prototype

A vararg function pushes all parameters on the stack. The problem is that, if a prototype is not provided, the compiler uses the normal ABI and puts the parameters in registers so they are not read correctly by the called function.

Redesign ABI so it works correctly in this case.

Assertion failure in ExpandSELECT

Assertion failed: (VT.isVector() && !Mask.getValueType().isVector() && Op1.getValueType() == Op2.getValueType() && "Invalid type"), function ExpandSELECT, file /Users/jeffbush/src/NyuziToolchain/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp, line 721.
0  llc                      0x00000001060d75dc llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  llc                      0x00000001060d7b59 PrintStackTraceSignalHandler(void*) + 25
2  llc                      0x00000001060d3b79 llvm::sys::RunSignalHandlers() + 425
3  llc                      0x00000001060d7ff2 SignalHandler(int) + 354
4  libsystem_platform.dylib 0x00007fff8cb2bbba _sigtramp + 26
5  libsystem_platform.dylib 0x000000005b130a78 _sigtramp + 3462418136
6  libsystem_c.dylib        0x00007fff8c9b2420 abort + 129
7  libsystem_c.dylib        0x00007fff8c979893 basename_r + 0
8  llc                      0x0000000105d5fa35 (anonymous namespace)::VectorLegalizer::ExpandSELECT(llvm::SDValue) + 517
9  llc                      0x0000000105d5bbe2 (anonymous namespace)::VectorLegalizer::Expand(llvm::SDValue) + 434
10 llc                      0x0000000105d58356 (anonymous namespace)::VectorLegalizer::LegalizeOp(llvm::SDValue) + 4310
11 llc                      0x0000000105d56a4d (anonymous namespace)::VectorLegalizer::Run() + 1437
12 llc                      0x0000000105d56432 llvm::SelectionDAG::LegalizeVectors() + 66
13 llc                      0x0000000105ed9376 llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 6566
14 llc                      0x0000000105ed788e llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&) + 270
15 llc                      0x0000000105ed5f82 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 5506
16 llc                      0x0000000105ed307b llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1643
17 llc                      0x0000000105185ec1 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 449
18 llc                      0x000000010568d18f llvm::FPPassManager::runOnFunction(llvm::Function&) + 

Occurs with the following code (generated by llvm-stress)

define void @autogen_SD8396() {
BB:
  br label %CF864

CF864:                                            ; preds = %CF864, %BB
  br i1 undef, label %CF864, label %CF875

CF875:                                            ; preds = %CF864
  %FC303 = uitofp <4 x i1> undef to <4 x float>
  %Sl320 = select i1 undef, <4 x float> %FC303, <4 x float> undef
  br label %CF826

CF826:                                            ; preds = %CF826, %CF875
  %Shuff332 = shufflevector <4 x float> undef, <4 x float> %Sl320, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  br label %CF826
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.