@@ -63,8 +63,7 @@ def select_same_val_self (rewriter : PatternRewriter OpCode) (op : OperationPtr)
6363def select_constant_cmp_true_local (ctx : WfIRContext OpCode) (op : OperationPtr) :
6464 Option (WfIRContext OpCode × Option (Array OperationPtr × Array ValuePtr)) := do
6565 let some (cond, tval, _fval) := matchSelect op ctx.raw | return (ctx, none)
66- let some cst := matchConstantIntVal cond ctx.raw | return (ctx, none)
67- if cst ≠ 1 then return (ctx, none)
66+ if !isConstantOne cond ctx.raw then return (ctx, none)
6867 some (ctx, some (#[], #[tval]))
6968
7069def select_constant_cmp_true (rewriter : PatternRewriter OpCode) (op : OperationPtr)
@@ -958,6 +957,9 @@ def select_neg1_0_local (ctx : WfIRContext OpCode) (op : OperationPtr) :
958957 if ct ≠ -1 then return (ctx, none)
959958 let some cf := matchConstantIntVal fv ctx.raw | return (ctx, none)
960959 if cf ≠ 0 then return (ctx, none)
960+ -- At i1, -1 is true and no extension is needed.
961+ if (op.getResult 0 : ValuePtr).getType! ctx.raw = IntegerType.mk 1 then
962+ return (ctx, some (#[], #[cond]))
961963 let (ctx, newOp) ← WfRewriter.createOp! ctx Llvm.sext #[(op.getResult 0 : ValuePtr).getType! ctx.raw] #[cond]
962964 #[] #[] () none
963965 some (ctx, some (#[newOp], #[newOp.getResult 0 ]))
@@ -1002,6 +1004,8 @@ def select_0_neg1_local (ctx : WfIRContext OpCode) (op : OperationPtr) :
10021004 #[] #[] m1 none
10031005 let (ctx, ncond) ← WfRewriter.createOp! ctx Llvm.xor #[cond.getType! ctx.raw] #[cond, (c1.getResult 0 )]
10041006 #[] #[] () none
1007+ if (op.getResult 0 : ValuePtr).getType! ctx.raw = IntegerType.mk 1 then
1008+ return (ctx, some (#[c1, ncond], #[ncond.getResult 0 ]))
10051009 let (ctx, newOp) ← WfRewriter.createOp! ctx Llvm.sext #[(op.getResult 0 : ValuePtr).getType! ctx.raw] #[(ncond.getResult 0 )]
10061010 #[] #[] () none
10071011 some (ctx, some (#[c1, ncond, newOp], #[newOp.getResult 0 ]))
0 commit comments