Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
53 views

I'm new to LLVM Backend development and I'm discovering some of its working by modifying an existing backend, compiling the llvm-project and observing the changes brought to the binaries and their ...
Ilyass's user avatar
  • 1
1 vote
1 answer
1k views

I have read this doc and first chapter of this example. The doc and example are really good at helping me understanding backend of compiler and LLVM. However, they still not answering the question of ...
Shore's user avatar
  • 1,069
1 vote
0 answers
269 views

I have fetched LLVM-IR via clang -S -emit-llvm demo.c where demo.c is as follows int demo(int a, int b){ int c = a+b; return c; } The IR looks like define dso_local i32 @demo(i32 %0, i32 %1) #0 { %...
pralay das's user avatar
0 votes
1 answer
444 views

I've started playing with LLVM, making a pet language. I'm using the C-API. I have a parser and basic AST, but I am at a bit of a road block with LLVM. The following is a minified version of my code ...
Zachary Vander Klippe's user avatar
0 votes
1 answer
629 views

I'm relatively new to LLVM, and I'm attempting to generate LLVM IR that calls a C function (growDictionary). This is on x86_64 Linux, using llvm 12: $ llc-12 --version Ubuntu LLVM version 12.0.1 ...
Tudor Bosman's user avatar
4 votes
1 answer
464 views

Why is clang turning fabs(double) into vandps instead of vandpd (like GCC does)? Example from Compiler Explorer: #include <math.h> double float_abs(double x) { return fabs(x); } clang 12....
soc's user avatar
  • 28.5k
2 votes
0 answers
566 views

I'm using the LLVM-C API for a compiler project and need to emit object code from IR to an in memory buffer. I'm aware the JIT can do this, but the resulting code will be executed many times with ...
muke's user avatar
  • 436
3 votes
0 answers
737 views

From the command line it is possible to tell clang to disable use of some features, for example -mno-mmx or -mno-popcnt. However, while cmov is a feature tracked by llvm, there is no -mno-cmov for ...
PluckyBird's user avatar
1 vote
1 answer
924 views

Trying to generate a very simple object file with LLVM-C. Unfortunately I'm still stuck on "TargetMachine can't emit a file of this type" tried reordering code and various things for CPU (x64-64, ...
Mirks's user avatar
  • 116
1 vote
2 answers
696 views

The LLVM MISched instruction scheduler uses declarative TableGen descriptions of the processor functional units, pipelines and latencies. Imagine trying to determine the equivalent of the coding ...
Olsonist's user avatar
  • 2,511
2 votes
0 answers
625 views

I have get an example llvm code from here. This code has some problems that I fixed them too. At this point, all it does is to dump the translated IR code. What I am after is to create an executable ...
ar2015's user avatar
  • 6,250
2 votes
0 answers
43 views

In rustc, there are 4 code models. You can see the list by typing rustc --print code-models: Available code models: small kernel medium large What do they mean?
William Taylor's user avatar
1 vote
0 answers
291 views

I have been trying to invoke my out-of-tree LLVM Function pass using clang (opt is not an option. Works fine with opt btw): clang -std=c99 -m64 -c -o file.o -DSPEC -DNDEBUG -Ispec_qsort -...
sk10's user avatar
  • 73
11 votes
1 answer
6k views

Rust treats signed integer overflow differently in debug and release mode. When it happens, Rust panics in debug mode while silently performs two's complement wrapping in release mode. As far as I ...
Zhiyao's user avatar
  • 4,524
15 votes
1 answer
814 views

LLVM appears to ignore core::intrinsics::assume(..) calls. They do end up in the bytecode, but don't change the resulting machine code. For example take the following (nonsensical) code: pub fn one(...
llogiq's user avatar
  • 14.6k
11 votes
3 answers
595 views

Here's a simple C file with an enum definition and a main function: enum days {MON, TUE, WED, THU}; int main() { enum days d; d = WED; return 0; } It transpiles to the following LLVM IR: ...
macleginn's user avatar
  • 341
7 votes
1 answer
670 views

I've written this very simple Rust function: fn iterate(nums: &Box<[i32]>) -> i32 { let mut total = 0; let len = nums.len(); for i in 0..len { if nums[i] > 0 { ...
Dathan's user avatar
  • 7,476
1 vote
0 answers
541 views

This question is quite similar to this one, but I am not realy sure how to get the size in the following situation: I have a Pointer type, e.g. i32*. Now I would like to get the size of the 'pointed-...
mame98's user avatar
  • 1,371
261 votes
2 answers
24k views

When running a sum loop over an array in Rust, I noticed a huge performance drop when CAPACITY >= 240. CAPACITY = 239 is about 80 times faster. Is there special compilation optimization Rust is ...
Guy Korland's user avatar
  • 9,598
198 votes
4 answers
41k views

Rust has 128-bit integers, these are denoted with the data type i128 (and u128 for unsigned ints): let a: i128 = 170141183460469231731687303715884105727; How does Rust make these i128 values work on ...
ruohola's user avatar
  • 24.9k
423 votes
1 answer
54k views

As far as I know, reference/pointer aliasing can hinder the compiler's ability to generate optimized code, since they must ensure the generated binary behaves correctly in the case where the two ...
Zhiyao's user avatar
  • 4,524
12 votes
1 answer
460 views

On page 322 of Programming Rust by Blandy and Orendorff is this claim: ...Rust...recognizes that there's a simpler way to sum the numbers from one to n: the sum is always equal to n * (n+1) / 2. ...
Kyle Strand's user avatar
  • 16.5k
575 votes
6 answers
42k views

I know that an "undefined behaviour" in C++ can pretty much allow the compiler to do anything it wants. However, I had a crash that surprised me, as I assumed that the code was safe enough. In this ...
Remz's user avatar
  • 3,428
16 votes
1 answer
5k views

I am disassembling this code on llvm clang Apple LLVM version 8.0.0 (clang-800.0.42.1): int main() { float a=0.151234; float b=0.2; float c=a+b; printf("%f", c); } I compiled with no -...
Stefano Borini's user avatar
2 votes
3 answers
671 views

The code is naive: use std::time; fn main() { const NUM_LOOP: u64 = std::u64::MAX; let mut sum = 0u64; let now = time::Instant::now(); for i in 0..NUM_LOOP { sum += i; } ...
Sanhu Li's user avatar
  • 457
-6 votes
2 answers
314 views

I have two (equivalent?) programs, one in Go the other in Rust. The average execution time is: Go ~169ms Rust ~201ms Go package main import ( "fmt" "time" ) func main() { work := []...
Kyle's user avatar
  • 11
10 votes
1 answer
564 views

I have a Box<dyn Any> and I know the underlying type so I want to optimize away the test in Box::downcast() (source). First I tried with std::hint::unreachable_unchecked(): pub unsafe fn ...
Tim Diekmann's user avatar
  • 8,624
2 votes
1 answer
2k views

If I compile with cargo rustc -- --emit=llvm-ir the compiler will emit LLVM IR. Here are the LLVM passes that Rust uses. What LLVM passes, if any, have been performed on the emitted IR? Is there any ...
HiDefender's user avatar
  • 2,448
1 vote
1 answer
154 views

If the loops are of the different type then I can easily identify them with the name but if there are multiple same type loops (say 5 while loops), how can I identify what basic block in the LLVM IR ...
Sanjit Kumar Mishra's user avatar
17 votes
2 answers
7k views

I am currently playing around with LLVM and am trying to write a few optimizers to familiarize myself with opt and clang. I wrote a test.c file that is as follow: int foo(int aa, int bb, int cc){ ...
Brenda So's user avatar
  • 211
35 votes
3 answers
21k views

Executing rustc -C help shows (among other things): -C opt-level=val -- optimize with possible levels 0-3, s, or z The levels 0 to 3 are fairly intuitive, I think: the higher the level, the more ...
Lukas Kalbertodt's user avatar
15 votes
1 answer
3k views

I wanted to take a look at the assembly output for a tiny Rust function: pub fn double(n: u8) -> u8 { n + n } I used the Godbolt Compiler Explorer to generate and view the assembly (with the -...
Lukas Kalbertodt's user avatar
16 votes
4 answers
6k views

I wrote a simple C++ function in order to check compiler optimization: bool f1(bool a, bool b) { return !a || (a && b); } After that I checked the equivalent in Rust: fn f1(a: bool, b: ...
Mariusz Jaskółka's user avatar
15 votes
2 answers
6k views

I have a function where Rust's/LLVM's optimization fails and leads to a panic (in the release version), while the unoptimized code (debug version) just works fine. If I compare the generated assembly ...
Matthias's user avatar
  • 8,240
6 votes
4 answers
8k views

How can I ensure that a function with no side effects gets executed and doesn't get optimized away in stable Rust? Is there an attribute combination I could use, or must I call another function with ...
Doe's user avatar
  • 695
28 votes
1 answer
906 views

The following example of pointer aliasing: pub unsafe fn f(a: *mut i32, b: *mut i32, x: *const i32) { *a = *x; *b = *x; } compiles into the following assembly (with -C opt-level=s): example::f: ...
Cornstalks's user avatar
  • 38.5k
11 votes
3 answers
2k views

When writing integer functions in Rust which will run millions of times (think pixel processing), it's useful to use operations with the highest performance - similar to C/C++. While the reference ...
ideasman42's user avatar
  • 49.4k
30 votes
2 answers
5k views

Consider the snippet struct Foo { dummy: [u8; 65536], } fn bar(foo: Foo) { println!("{:p}", &foo) } fn main() { let o = Foo { dummy: [42u8; 65536] }; println!("{:p}", &o); ...
WiSaGaN's user avatar
  • 48.4k
142 votes
1 answer
36k views

Rust has an "inline" attribute that can be used in one of those three flavors: #[inline] #[inline(always)] #[inline(never)] When should they be used? In the Rust reference, we see an inline ...
WiSaGaN's user avatar
  • 48.4k
29 votes
1 answer
2k views

I'm writing a linear algebra library in Rust. I have a function to get a reference to a matrix cell at a given row and column. This function starts with a pair of assertions that the row and column ...
Bradley Hardy's user avatar
12 votes
1 answer
2k views

Starting with this simple C program: void nothing(void) {} int main() { int i; for (i = 0; i < 10; ++i) { nothing(); } return 0; } My passes output as follows: Note: IR statements ...
Ahmed Ghoneim's user avatar
5 votes
1 answer
663 views

I am working on a Rust crate which changes the rounding mode (+inf, -inf, nearest, or truncate). The functions that change the rounding mode are written using inline assembly: fn upward() { let ...
Houss_gc's user avatar
  • 759
21 votes
2 answers
4k views

I'm trying to benchmark some Rust code, but I can't figure out how to set the "ffast-math" option. % rustc -C opt-level=3 -C llvm-args='-enable-unsafe-fp-math' unrolled.rs rustc: Unknown command line ...
yong's user avatar
  • 3,643
4 votes
1 answer
1k views

I'm starting to read LLVM docs and IR documentation. In common architectures, an asm cmp instruction "result" value is -at least- 3 bits long, let's say the first bit is the SIGN flag, the second bit ...
Lucio M. Tato's user avatar
13 votes
2 answers
4k views

I've got a compiler written with LLVM and I'm looking to up my ABI compliance. For example, I've found it hard to actually find specification documents for C ABI on Windows x86 or Linux. And the ones ...
Puppy's user avatar
  • 148k
29 votes
1 answer
17k views

The LLVM language specifies integer types as iN, where N is the bit-width of the integer, and ranges from 1 to 2^23-1 (According to: http://llvm.org/docs/LangRef.html#integer-type) I have 2 questions:...
Ali J's user avatar
  • 362