llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.09k stars 11.6k forks source link

How can I disable the ext from i16 to i32 in Clang? When can Clang generate @llvm.sadd.with.overflow.i16? #66170

Closed zhping8080 closed 1 year ago

zhping8080 commented 1 year ago

I find that when two i16 numbers or i8 numbers are added, it will be extended to i32. Even if I choose to compile it with '-fsanitize=undefined'. So, How can generate the intrinsic 'call @llvm.sadd.with.overflow.i16' ? Additional, how can I find the implementation of llvm.sadd.with.overflow.* in LLVM source code? It's a bit challenging for newbies. Thanks!

image
topperc commented 1 year ago

You can use __builtin_add_overflow. See https://godbolt.org/z/6qsPqaWz3 for example.

llvm.sadd.with.overflow is converted to ISD::SADDO in SelectionDAG. How it is handled after that is target specific.

zhping8080 commented 1 year ago

Thank you very much!