Skip to content

Commit

Permalink
feat: fix select semantics to lazily evaluate arguments (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
bollu authored Nov 13, 2023
1 parent 8ce82f1 commit b51dfa6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion SSA/Projects/InstCombine/AliveStatements.lean
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ theorem bitvec_1030 :
∀ (w : Nat) (X : BitVec w), sdiv? X (-1) ⊑ some (0 - X)
:= by alive_auto
try sorry

/-
theorem bitvec_Select_846:
∀ (C B : BitVec 1), select B (ofBool true) C = B ||| C
:= by alive_auto
Expand Down Expand Up @@ -474,6 +474,7 @@ theorem bitvec_Select_1105 :
∀ (w : Nat) (Y X : BitVec w), select (ofBool false) X Y = Y
:= by alive_auto
try sorry
-/

theorem bitvec_InstCombineShift__239 :
∀ (w : Nat) (X C : BitVec w), X <<< C >>> C = X &&& (-1) >>> C
Expand Down
4 changes: 3 additions & 1 deletion SSA/Projects/InstCombine/Base.lean
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def Op.denote (o : Op) (arg : HVector Goedel.toType (OpSignature.sig o)) :
| Op.not _ => Option.map (~~~.) arg.toSingle
| Op.copy _ => arg.toSingle
| Op.neg _ => Option.map (-.) arg.toSingle
| Op.select _ => tripleBind select? arg.toTriple
| Op.select _ =>
let (ocond, otrue, ofalse) := arg.toTriple
select? ocond otrue ofalse
| Op.icmp c _ => pairBind (icmp? c) arg.toPair

instance : OpDenote Op Ty := ⟨
Expand Down
12 changes: 5 additions & 7 deletions SSA/Projects/InstCombine/LLVM/Semantics.lean
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,14 @@ def ashr? {m n k} (op1 : BitVec n) (op2 : BitVec m) : Option (BitVec k) :=

/--
If the condition is an i1 and it evaluates to 1, the instruction returns the first value argument; otherwise, it returns the second value argument.
-/
def select {w : Nat} (c : BitVec 1) (x y : BitVec w) : BitVec w :=
cond (c.toNat != 0) x y
/--
Wrapper around `select` (this cannot become `none` on its own)
If the condition is an i1 and it evaluates to 1, the instruction returns the first value argument; otherwise, it returns the second value argument.
-/
def select? {w : Nat} (c : BitVec 1) (x y : BitVec w) : Option (BitVec w) :=
Option.some <| select c x y
def select? {w : Nat} (c? : Option (BitVec 1)) (x? y? : Option (BitVec w)) : Option (BitVec w) :=
match c? with
| .none => .none
| .some true => x?
| .some false => y?

inductive IntPredicate where
| eq
Expand Down

0 comments on commit b51dfa6

Please sign in to comment.