Skip to content

Commit

Permalink
fix: Add LLVM lowering for logic.Not
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-koch committed Dec 18, 2024
1 parent e065d70 commit 63542a2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hugr-llvm/src/extension/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ fn emit_logic_op<'c, H: HugrView>(
}
acc
}
LogicOp::Not => {
let x = inputs[0];
builder.build_not(x, "")?
}
op => {
return Err(anyhow!("LogicOpEmitter: Unknown op: {op:?}"));
}
Expand Down Expand Up @@ -140,4 +144,11 @@ mod test {
let hugr = test_logic_op(LogicOp::Eq, 2);
check_emission!(hugr, llvm_ctx);
}

#[rstest]
fn not(mut llvm_ctx: TestContext) {
llvm_ctx.add_extensions(add_logic_extensions);
let hugr = test_logic_op(LogicOp::Not, 1);
check_emission!(hugr, llvm_ctx);
}
}
18 changes: 18 additions & 0 deletions hugr-llvm/src/extension/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: hugr-llvm/src/extension/logic.rs
expression: mod_str
---
; ModuleID = 'test_context'
source_filename = "test_context"

define { i32, {}, {} } @_hl.main.1({ i32, {}, {} } %0) {
alloca_block:
br label %entry_block

entry_block: ; preds = %alloca_block
%1 = extractvalue { i32, {}, {} } %0, 0
%2 = xor i32 %1, -1
%3 = trunc i32 %2 to i1
%4 = select i1 %3, { i32, {}, {} } { i32 1, {} poison, {} undef }, { i32, {}, {} } { i32 0, {} undef, {} poison }
ret { i32, {}, {} } %4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
source: hugr-llvm/src/extension/logic.rs
expression: mod_str
---
; ModuleID = 'test_context'
source_filename = "test_context"

define { i32, {}, {} } @_hl.main.1({ i32, {}, {} } %0) {
alloca_block:
%"0" = alloca { i32, {}, {} }, align 8
%"2_0" = alloca { i32, {}, {} }, align 8
%"4_0" = alloca { i32, {}, {} }, align 8
br label %entry_block

entry_block: ; preds = %alloca_block
store { i32, {}, {} } %0, { i32, {}, {} }* %"2_0", align 4
%"2_01" = load { i32, {}, {} }, { i32, {}, {} }* %"2_0", align 4
%1 = extractvalue { i32, {}, {} } %"2_01", 0
%2 = xor i32 %1, -1
%3 = trunc i32 %2 to i1
%4 = select i1 %3, { i32, {}, {} } { i32 1, {} poison, {} undef }, { i32, {}, {} } { i32 0, {} undef, {} poison }
store { i32, {}, {} } %4, { i32, {}, {} }* %"4_0", align 4
%"4_02" = load { i32, {}, {} }, { i32, {}, {} }* %"4_0", align 4
store { i32, {}, {} } %"4_02", { i32, {}, {} }* %"0", align 4
%"03" = load { i32, {}, {} }, { i32, {}, {} }* %"0", align 4
ret { i32, {}, {} } %"03"
}

0 comments on commit 63542a2

Please sign in to comment.