Skip to content

Support the disjoint flag in or instructions (introduced in LLVM 18) #335

@RyanGlScott

Description

@RyanGlScott

LLVM 18 adds a disjoint flag to or instructions (see commit llvm/llvm-project@d9962c4). Per the LLVM Language Reference, this can affect the semantics of or:

disjoint means that for each bit, that bit is zero in at least one of the inputs. This allows the Or to be treated as an Add since no carry can occur from any bit. If the disjoint keyword is present, the result value of the or is a poison value if both inputs have a one in the same bit position. For vectors, only the element containing the bit is poison.

I am having trouble getting Clang to emit a disjoint flag from a C program, so instead, here is a minimal LLVM test case that uses it (adapted from here):

define i64 @test_or(i64 %a, i64 %b) {
  %res = or disjoint i64 %a, %b
  ret i64 %res
}

Currently, llvm-pretty-bc-parser parses this program, but this is because it ignores the disjoint flag entirely. If you try to roundtrip the test case above through llvm-pretty-bc-parser, it will drop disjoint:

λ> :m + Text.LLVM.PP Data.LLVM.BitCode
λ> parseBitCodeFromFileWithWarnings "test.bc" >>= either (putStrLn . formatError) (print . ppLLVM llvmVlatest ppModule . fst)
source_filename = "test.ll"
target triple = "unknown-unknown-unknown-unknown-"
define default i64 @test_or(i64 %a, i64 %b) {
; <label>: 0
  %res = or i64 %a, %b
  ret i64 %res
}

We will need to augment the definition of Or on the llvm-pretty side to store this extra disjoint flag, and we will need to update the logic for parsing Or instructions here in llvm-pretty-bc-parser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions