Enzyme-JAX icon indicating copy to clipboard operation
Enzyme-JAX copied to clipboard

[arith] Missing canonicalize

Open wsmoses opened this issue 11 months ago • 2 comments

2025-05-05T21:16:27.7201942Z       %737 = arith.extui %736 : i1 to i64
2025-05-05T21:16:27.7202195Z       %738 = arith.cmpi eq, %737, %c0_i64 : i64

wsmoses avatar May 06 '25 02:05 wsmoses

also:

2025-05-05T21:16:27.7206944Z       %753 = arith.index_castui %752 : i32 to index
2025-05-05T21:16:27.7207203Z       %754 = arith.cmpi eq, %753, %c0 : index

wsmoses avatar May 06 '25 02:05 wsmoses

actually the entirety of the following just is littered with arith canonicalizations (doing the ones above then lead to cmp of select, and etc):


2025-05-05T21:16:27.7196241Z     %13:2 = scf.while (%arg25 = %c1_i64, %arg26 = %c24_i64) : (i64, i64) -> (i64, i64) {
2025-05-05T21:16:27.7196572Z       %721 = arith.shrui %arg26, %c1_i64 : i64
2025-05-05T21:16:27.7197058Z       %722 = arith.addi %arg25, %721 : i64
2025-05-05T21:16:27.7197303Z       %723 = arith.addi %722, %c-1_i64 : i64
2025-05-05T21:16:27.7197557Z       %724 = arith.sitofp %723 : i64 to f64
2025-05-05T21:16:27.7197875Z       %725 = arith.mulf %724, %cst {fastmathFlags = #llvm.fastmath<none>} : f64
2025-05-05T21:16:27.7198272Z       %726 = arith.mulf %724, %cst_0 {fastmathFlags = #llvm.fastmath<none>} : f64
2025-05-05T21:16:27.7198594Z       %727 = math.absf %725 : f64
2025-05-05T21:16:27.7198910Z       %728 = arith.cmpf olt, %cst_1, %727 {fastmathFlags = #llvm.fastmath<none>} : f64
2025-05-05T21:16:27.7199256Z       %729 = arith.select %728, %725, %cst_1 : f64
2025-05-05T21:16:27.7199519Z       %730 = arith.select %728, %cst_1, %725 : f64
2025-05-05T21:16:27.7199841Z       %731 = arith.addf %729, %730 {fastmathFlags = #llvm.fastmath<none>} : f64
2025-05-05T21:16:27.7200230Z       %732 = arith.subf %729, %731 {fastmathFlags = #llvm.fastmath<none>} : f64
2025-05-05T21:16:27.7200622Z       %733 = arith.addf %730, %732 {fastmathFlags = #llvm.fastmath<none>} : f64
2025-05-05T21:16:27.7201009Z       %734 = arith.addf %726, %733 {fastmathFlags = #llvm.fastmath<none>} : f64
2025-05-05T21:16:27.7201404Z       %735 = arith.addf %731, %734 {fastmathFlags = #llvm.fastmath<none>} : f64
2025-05-05T21:16:27.7201716Z       %736 = math.isnan %735 : f64

2025-05-05T21:16:27.7201942Z       %737 = arith.extui %736 : i1 to i64
2025-05-05T21:16:27.7202195Z       %738 = arith.cmpi eq, %737, %c0_i64 : i64

2025-05-05T21:16:27.7202445Z       %739 = math.isnan %1 : f64
2025-05-05T21:16:27.7202666Z       %740 = arith.extui %739 : i1 to i64
2025-05-05T21:16:27.7202911Z       %741 = arith.cmpi eq, %740, %c0_i64 : i64
2025-05-05T21:16:27.7203160Z       %742 = arith.extui %741 : i1 to i32
2025-05-05T21:16:27.7203403Z       %743 = arith.bitcast %735 : f64 to i64
2025-05-05T21:16:27.7203675Z       %744 = arith.xori %743, %c9223372036854775807_i64 : i64
2025-05-05T21:16:27.7203955Z       %745 = arith.cmpi sge, %743, %c0_i64 : i64
2025-05-05T21:16:27.7204301Z       %746 = arith.select %745, %743, %744 {fastmathFlags = #llvm.fastmath<none>} : i64
2025-05-05T21:16:27.7204890Z       %747 = arith.bitcast %1 : f64 to i64
2025-05-05T21:16:27.7205163Z       %748 = arith.xori %747, %c9223372036854775807_i64 : i64
2025-05-05T21:16:27.7205444Z       %749 = arith.cmpi sge, %747, %c0_i64 : i64
2025-05-05T21:16:27.7205873Z       %750 = arith.select %749, %747, %748 {fastmathFlags = #llvm.fastmath<none>} : i64
2025-05-05T21:16:27.7206224Z       %751 = arith.cmpi slt, %746, %750 : i64

2025-05-05T21:16:27.7206480Z       %752 = arith.select %738, %742, %c0_i32 : i32

2025-05-05T21:16:27.7206944Z       %753 = arith.index_castui %752 : i32 to index
2025-05-05T21:16:27.7207203Z       %754 = arith.cmpi eq, %753, %c0 : index

2025-05-05T21:16:27.7207452Z       %755 = arith.cmpi ne, %753, %c0 : index

2025-05-05T21:16:27.7207696Z       %756 = arith.andi %754, %738 : i1
2025-05-05T21:16:27.7207929Z       %757 = arith.andi %755, %751 : i1

2025-05-05T21:16:27.7208158Z       %758 = arith.ori %756, %757 : i1

2025-05-05T21:16:27.7208393Z       %759 = arith.addi %722, %c1_i64 : i64
2025-05-05T21:16:27.7208637Z       %760 = arith.subi %c0_i64, %721 : i64
2025-05-05T21:16:27.7208875Z       %761 = arith.addi %760, %arg26 : i64
2025-05-05T21:16:27.7209118Z       %762 = arith.addi %761, %c-1_i64 : i64
2025-05-05T21:16:27.7209363Z       %763 = arith.select %758, %762, %721 : i64
2025-05-05T21:16:27.7209623Z       %764 = arith.select %758, %759, %arg25 : i64
2025-05-05T21:16:27.7209885Z       %765 = arith.cmpi ne, %763, %c0_i64 : i64
2025-05-05T21:16:27.7210140Z       scf.condition(%765) %764, %763 : i64, i64
2025-05-05T21:16:27.7210374Z     } do {
2025-05-05T21:16:27.7210546Z     ^bb0(%arg25: i64, %arg26: i64):
2025-05-05T21:16:27.7210778Z       scf.yield %arg25, %arg26 : i64, i64
2025-05-05T21:16:27.7211000Z     }

wsmoses avatar May 06 '25 02:05 wsmoses