Skip to content

Conversation

@Lancern
Copy link
Member

@Lancern Lancern commented Sep 14, 2024

This PR adds CIRGen support for the following 3 builtins related to compile- time assumptions:

  • __builtin_assume
  • __builtin_assume_aligned
  • __builtin_assume_separate_storage

3 new operations are invented to represent the three builtins.

LLVMIR lowering for these builtins cannot be implemented at this moment due to the lack of operand bundle support in LLVMIR dialect.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat, thanks! One minor observation

//===----------------------------------------------------------------------===//

def AssumeOp : CIR_Op<"assume"> {
let summary = "Tell the optimizer that a boolean value is true";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to mark this operation with some type of side-effect otherwise we'll make the situation with canonicalization worse (it will silently strip those away). We should probably have a simple CIR to CIR test using the canonicalizer and checking they don't get stripped away.

Looks like both AssumeOp and AssumeSepStorageOp need that (but perhaps not AssumeAlignedOp given the result is usually used?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test in clang/test/CIR/Transforms/builtin-assume.cir but it seems that neither -cir-simplify nor --canonicalize erases these operations. Are there any other canonicalization passes that could do such optimization?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting, I'd have expected these to be doing it (as they usually do for other operations), well at least there's a test to prevent that in case something off is going on in the meantime. Should be good for now, thanks for adding these.

This patch adds CIRGen support for the following 3 builtins related to compile-
time assumptions:
  - `__builtin_assume`
  - `__builtin_assume_aligned`
  - `__builtin_assume_separate_storage`

3 new operations are invented to represent the three builtins.

LLVMIR lowering for these builtins cannot be implemented at this moment due to
the lack of operand bundle support in LLVMIR dialect.
@Lancern
Copy link
Member Author

Lancern commented Sep 17, 2024

LLVMIR lowering for these builtins cannot be implemented at this moment due to the lack of operand bundle support in LLVMIR dialect.

BTW, I opened a PR in upstream to try to resolve this issue, see llvm/llvm-project#108933 .

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

//===----------------------------------------------------------------------===//

def AssumeOp : CIR_Op<"assume"> {
let summary = "Tell the optimizer that a boolean value is true";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting, I'd have expected these to be doing it (as they usually do for other operations), well at least there's a test to prevent that in case something off is going on in the meantime. Should be good for now, thanks for adding these.

@bcardosolopes bcardosolopes merged commit fe403ca into llvm:main Sep 17, 2024
@Lancern Lancern deleted the builtin-assume branch September 18, 2024 00:36
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This PR adds CIRGen support for the following 3 builtins related to
compile- time assumptions:
  - `__builtin_assume`
  - `__builtin_assume_aligned`
  - `__builtin_assume_separate_storage`

3 new operations are invented to represent the three builtins.

_LLVMIR lowering for these builtins cannot be implemented at this
moment_ due to the lack of operand bundle support in LLVMIR dialect.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This PR adds CIRGen support for the following 3 builtins related to
compile- time assumptions:
  - `__builtin_assume`
  - `__builtin_assume_aligned`
  - `__builtin_assume_separate_storage`

3 new operations are invented to represent the three builtins.

_LLVMIR lowering for these builtins cannot be implemented at this
moment_ due to the lack of operand bundle support in LLVMIR dialect.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This PR adds CIRGen support for the following 3 builtins related to
compile- time assumptions:
  - `__builtin_assume`
  - `__builtin_assume_aligned`
  - `__builtin_assume_separate_storage`

3 new operations are invented to represent the three builtins.

_LLVMIR lowering for these builtins cannot be implemented at this
moment_ due to the lack of operand bundle support in LLVMIR dialect.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This PR adds CIRGen support for the following 3 builtins related to
compile- time assumptions:
  - `__builtin_assume`
  - `__builtin_assume_aligned`
  - `__builtin_assume_separate_storage`

3 new operations are invented to represent the three builtins.

_LLVMIR lowering for these builtins cannot be implemented at this
moment_ due to the lack of operand bundle support in LLVMIR dialect.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
This PR adds CIRGen support for the following 3 builtins related to
compile- time assumptions:
  - `__builtin_assume`
  - `__builtin_assume_aligned`
  - `__builtin_assume_separate_storage`

3 new operations are invented to represent the three builtins.

_LLVMIR lowering for these builtins cannot be implemented at this
moment_ due to the lack of operand bundle support in LLVMIR dialect.
lanza pushed a commit that referenced this pull request Nov 5, 2024
This PR adds CIRGen support for the following 3 builtins related to
compile- time assumptions:
  - `__builtin_assume`
  - `__builtin_assume_aligned`
  - `__builtin_assume_separate_storage`

3 new operations are invented to represent the three builtins.

_LLVMIR lowering for these builtins cannot be implemented at this
moment_ due to the lack of operand bundle support in LLVMIR dialect.
lanza pushed a commit that referenced this pull request Mar 18, 2025
This PR adds CIRGen support for the following 3 builtins related to
compile- time assumptions:
  - `__builtin_assume`
  - `__builtin_assume_aligned`
  - `__builtin_assume_separate_storage`

3 new operations are invented to represent the three builtins.

_LLVMIR lowering for these builtins cannot be implemented at this
moment_ due to the lack of operand bundle support in LLVMIR dialect.
terapines-osc-cir pushed a commit to Terapines/clangir that referenced this pull request Sep 2, 2025
This PR adds CIRGen support for the following 3 builtins related to
compile- time assumptions:
  - `__builtin_assume`
  - `__builtin_assume_aligned`
  - `__builtin_assume_separate_storage`

3 new operations are invented to represent the three builtins.

_LLVMIR lowering for these builtins cannot be implemented at this
moment_ due to the lack of operand bundle support in LLVMIR dialect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants