()
| 1750 | |
| 1751 | #[test] |
| 1752 | fn aliases() { |
| 1753 | use crate::ir::InstBuilder; |
| 1754 | use crate::ir::condcodes::IntCC; |
| 1755 | |
| 1756 | let mut func = Function::new(); |
| 1757 | let block0 = func.dfg.make_block(); |
| 1758 | let mut pos = FuncCursor::new(&mut func); |
| 1759 | pos.insert_block(block0); |
| 1760 | |
| 1761 | // Build a little test program. |
| 1762 | let v1 = pos.ins().iconst(types::I32, 42); |
| 1763 | |
| 1764 | // Make sure we can resolve value aliases even when values is empty. |
| 1765 | assert_eq!(pos.func.dfg.resolve_aliases(v1), v1); |
| 1766 | |
| 1767 | let arg0 = pos.func.dfg.append_block_param(block0, types::I32); |
| 1768 | let (s, c) = pos.ins().uadd_overflow(v1, arg0); |
| 1769 | let iadd = match pos.func.dfg.value_def(s) { |
| 1770 | ValueDef::Result(i, 0) => i, |
| 1771 | _ => panic!(), |
| 1772 | }; |
| 1773 | |
| 1774 | // Remove `c` from the result list. |
| 1775 | pos.func.stencil.dfg.results[iadd].remove(1, &mut pos.func.stencil.dfg.value_lists); |
| 1776 | |
| 1777 | // Replace `uadd_overflow` with a normal `iadd` and an `icmp`. |
| 1778 | pos.func.replace(iadd).iadd(v1, arg0); |
| 1779 | let c2 = pos.ins().icmp(IntCC::Equal, s, v1); |
| 1780 | pos.func.dfg.change_to_alias(c, c2); |
| 1781 | |
| 1782 | assert_eq!(pos.func.dfg.resolve_aliases(c2), c2); |
| 1783 | assert_eq!(pos.func.dfg.resolve_aliases(c), c2); |
| 1784 | } |
| 1785 | |
| 1786 | #[test] |
| 1787 | fn cloning() { |
nothing calls this directly
no test coverage detected