llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

(llvm 3.3) SHLX64rm assertion in JIT codegen

Open vtjnash opened this issue 13 years ago • 6 comments

Bugzilla Link 17422
Resolution FIXED
Resolved on Feb 09, 2021 02:42
Version 3.3
OS All
CC @topperc,@jdoerfert,@RKSimon,@darkbuck,@phoebewang,@rotateright

Extended Description

On the Haswell platform, it seems the SHLX64rm instruction causes an assertion failure in the JIT. Unfortunately, I have not been able to make a reduced test case.

Unknown immediate size UNREACHABLE executed at /home/jameson/julia/deps/llvm-3.3/lib/Target/X86/MCTargetDesc/X86BaseInfo.h:497! %RSI = SHLX64rm %RBP, 1, %noreg, -120, %noreg, %RAX; mem:LD8[FixedStack3]

In gdb, I see that TSFlags&X86II::ImmMask = 0, so I guess this means it is missing some metadata from somewhere?

I'm not sure where to go from here, other than disabling the Haswell instruction set.

(on a side note, llvm 3.3 seems to be missing from the bug version target list)

vtjnash avatar Oct 01 '13 05:10 vtjnash

X86CodeEmitter.cpp is gone, along with all of the ancient JIT

commit 79cc1e3ae7bc224fa948495ba2f1c02f4c0c84ea Author: Eric Christopher [email protected] Date: Tue Sep 2 22:28:02 2014 +0000

vtjnash avatar Feb 09 '21 04:02 vtjnash

Yes, that patch seems to works. Thanks.

vtjnash avatar Oct 25 '13 08:10 vtjnash

Simple fix Try the attached patch. This bug is an issue specific to the old code emitter, which lags behind MC code emitter for a while. If possible, please try MCJIT as an alternative one.

darkbuck avatar Oct 25 '13 07:10 darkbuck

Modified Kaleidoscope JIT for working on Haswell bug Compile example:

clang++ -g kaleidoscope_for_shlx_bug.cpp llvm-config --cppflags --ldflags --libs core jit native -O3 -o kaleidoscope_shlx -rdynamic

(drop the -rdynamic flag for non-linux systems)

{ and } are newly added SHL and ASHR instructions, so we can generate a SHLX64rr instruction with the following code:

def shlx64rr(x) x { x; shlx64rr(10);

vtjnash avatar Oct 24 '13 06:10 vtjnash

my "testcase" was the entire Julia programming language :/

I modified the Kaleidoscope example to use int64 values, added a shift left instruction, forceable enabled the +BMI2 instructions, and ran in GCC (so it would crash and I could inspect the assembly code generated) and ran it in Intel's SDE with Haswell emulation. I can get it to generate the SHLX64rr instruction fine. I have not been able to generate the SHLX64rm instruction (it seems to prefer the SHLQ instruction). In fact, I see now that the tests for SHLX in test/CodeGen/X86/shift-bmi2.ll appear to only test for whether the reg,imm variant of the instruction is not generated.

vtjnash avatar Oct 24 '13 06:10 vtjnash

could you post the test case? a reduced one would be better.

darkbuck avatar Oct 15 '13 22:10 darkbuck