clangir icon indicating copy to clipboard operation
clangir copied to clipboard

CIR generated LLVM code for pointer arithmetic misses inbounds

Open ghehg opened this issue 1 year ago • 8 comments

sample code void foo(int *iptr) { iptr + 2; }

Clang generated code: https://godbolt.org/z/8Yjnhxhz4 where we have getelementptr inbounds i32, ptr %0, i64 2 CIR generated LLVM code is like https://godbolt.org/z/Wzdcvea46 where we see getelementptr i32, ptr %3, i64 2, We are missing inbounds here.

ghehg avatar Oct 08 '24 21:10 ghehg

up for take. If nobody picks it up, I'll fix it next week

ghehg avatar Oct 08 '24 23:10 ghehg

I can work on it to learn ClangIR.

liusy58 avatar Nov 27 '24 02:11 liusy58

@liusy58 welcome aboard! The website has some useful resources, and the Discord channel (use this link to join the LLVM Discord server if you haven't already) is a great place to ask questions (as is this issue). The general idea here would be to find the code in clang/lib/CodeGen that adds the appropriate attributes and then make the corresponding change under clang/lib/CIR/CodeGen.

smeenai avatar Nov 27 '24 17:11 smeenai

Thank you! I know that ClangIR is good for analysis and can make c++ safer. Apart from this, can we do something else?

liusy58 avatar Nov 28 '24 02:11 liusy58

Thank you! I know that ClangIR is good for analysis and can make c++ safer. Apart from this, can we do something else?

Thanks for willing to help out! Along this line of IR differences, depending on your interests, there are a couple of issues in my mind that we could use help.

  1. Support for elementwise builtins . Those could be really useful for vector intensive programs that use those builtins. And since relevant Ops are already defined in CIR and support vector type now, this should be a relatively starter rampup work.
  2. Comparing to classic clang codegen, CIR codegen still misses function call site and parameter attributes in the generated LLVM IR.

I'll create issues for above 2 issues by next Monday.

ghehg avatar Nov 28 '24 03:11 ghehg

Interesting topics. I love this!

liusy58 avatar Nov 28 '24 08:11 liusy58

Interesting topics. I love this! First issue: elementwise builtins https://github.com/llvm/clangir/issues/1192 The second issue already filed https://github.com/llvm/clangir/issues/1039

ghehg avatar Dec 02 '24 14:12 ghehg

Ok, thank you!

liusy58 avatar Dec 03 '24 07:12 liusy58