-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upstream a handwritten proof for alive - alive_DivRemOfSelectLa…
…rge proofs one (#262) * feat: upstream a handwritten proof for alive - alive_DivRemOfSelect This proof is factored out of #167 and is part of collection of proofs that we manually wrote to demonstrate the status of leans automation in BitVectors and such. * chore: golf * chore: golf more --- intro; rcases -> rintro. * chore: simp [simp_llvm] -> simp only [simp_llvm] --------- Co-authored-by: Siddharth Bhat <siddu.druid@gmail.com>
- Loading branch information
1 parent
a0fab68
commit efac4d7
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
SSA/Projects/InstCombine/AliveHandwrittenLargeExamples.lean
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import SSA.Projects.InstCombine.LLVM.EDSL | ||
import SSA.Projects.InstCombine.Tactic | ||
|
||
open BitVec | ||
open MLIR AST | ||
|
||
namespace AliveHandwritten | ||
|
||
namespace DivRemOfSelect | ||
|
||
/-- | ||
Name: SimplifyDivRemOfSelect | ||
precondition: true | ||
%sel = select %c, %Y, 0 | ||
%r = udiv %X, %sel | ||
=> | ||
%r = udiv %X, %Y | ||
-/ | ||
def alive_DivRemOfSelect_src (w : Nat) := | ||
[alive_icom (w)| { | ||
^bb0(%c: i1, %y : _, %x : _): | ||
%c0 = "llvm.mlir.constant" () { value = 0 : _ } :() -> (_) | ||
%v1 = "llvm.select" (%c,%y, %c0) : (i1, _, _) -> (_) | ||
%v2 = "llvm.udiv"(%x, %v1) : (_, _) -> (_) | ||
"llvm.return" (%v2) : (_) -> () | ||
}] | ||
|
||
def alive_DivRemOfSelect_tgt (w : Nat) := | ||
[alive_icom (w)| { | ||
^bb0(%c: i1, %y : _, %x : _): | ||
%v1 = "llvm.udiv" (%x,%y) : (_, _) -> (_) | ||
"llvm.return" (%v1) : (_) -> () | ||
}] | ||
|
||
theorem alive_DivRemOfSelect (w : Nat) : | ||
alive_DivRemOfSelect_src w ⊑ alive_DivRemOfSelect_tgt w := by | ||
unfold alive_DivRemOfSelect_src alive_DivRemOfSelect_tgt | ||
simp_alive_ssa | ||
simp_alive_undef | ||
simp only [simp_llvm] | ||
rintro y (rfl | ⟨vcond, hcond⟩) x | ||
-- | select condition is itself `none`, nothing more to be done. propagate the `none`. | ||
· cases x <;> cases y <;> simp | ||
· simp at hcond | ||
(obtain (rfl | rfl) : vcond = 1 ∨ vcond = 0 := by omega) <;> simp | ||
|
||
/--info: 'AliveHandwritten.DivRemOfSelect.alive_DivRemOfSelect' depends on | ||
axioms: [propext, Classical.choice, Quot.sound] -/ | ||
#guard_msgs in #print axioms alive_DivRemOfSelect | ||
|
||
end DivRemOfSelect | ||
|
||
end AliveHandwritten |