-
Notifications
You must be signed in to change notification settings - Fork 7
Description
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:
disjointmeans 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 thedisjointkeyword 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.