opencompl / lean-mlir

A minimal development of SSA theory
Other
88 stars 10 forks source link

Remove toNat from LLVM semantics #694

Closed tobiasgrosser closed 2 weeks ago

tobiasgrosser commented 2 weeks ago

Several LLVM functions use toNat, while they can use a bit-vector level comparison which would allow them to be bitblasted.

We should transform this code:

@[simp_llvm]
def lshr? {n} (op1 : BitVec n) (op2 : BitVec n) : IntW n :=
  let bits := op2.toNat
  if bits >= n then .none
  else pure (op1 >>> op2)

into

@[simp_llvm]
def lshr? {n} (op1 : BitVec n) (op2 : BitVec n) : IntW n :=
  let bits := op2
  if bits >= n then .none
  else pure (op1 >>> op2)

and while at it, clean it up to sth like:

@[simp_llvm]
def lshr? {n} (op1 : BitVec n) (op2 : BitVec n) : IntW n :=
  if op2 >= n then
    none
  else
    pure (op1 >>> op2)
lfrenot commented 2 weeks ago

Using BitVec.ofNat is fine, right?

tobiasgrosser commented 2 weeks ago

In which way? Why do you need it?

lfrenot commented 2 weeks ago

When you write op2 >= n in lshr, you're comparing a BitVec with a Nat I don't think this works properly But I may be wrong

tobiasgrosser commented 2 weeks ago

This should work in bv_decide.

tobiasgrosser commented 2 weeks ago

What is your concern?

lfrenot commented 2 weeks ago

This should work in bv_decide.

oh okay, then there is no issue indeed I'll do that and open a PR