llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
384 stars 100 forks source link

Codegen emits non-bool `cir.cmp` operations #1108

Open orbiri opened 4 days ago

orbiri commented 4 days ago

When looking at some C generated code I noticed that most cir.cmp operations that were generated were of type s32i, and then immediately converted to bool before used in if statements etc.

I found the root cause in CIRGenScalarExpr, will publish a fix over the coming week that simplifies the generated code for most cases.

———

I will note that a lot of tests rely on 1:1 generated CIR/LLVMIR, even without using file check variables, which makes such changes a lot harder than they could have been! For example, tests of lowering of complicated scopes and control flow should not check for the way that conditions are evaluated.

smeenai commented 4 days ago

This might be related to #480?

bcardosolopes commented 4 days ago

found the root cause in CIRGenScalarExpr, will publish a fix over the coming week that simplifies the generated code for most cases.

Nice!

tests of lowering of complicated scopes and control flow should not check for the way that conditions are evaluated

+1

This might be related to https://github.com/llvm/clangir/issues/480?

Are there cases related with i8-i1 as well?

orbiri commented 3 days ago

Uploaded fix + WIP tests in #1110

Still need to add some nice documentation, real commitdesc etc, and make all tests pass :)

orbiri commented 3 days ago

Unfortunately since #480 is in C++ this issue is unrelated.