> [...] > +;; Division > +(define_insn "div<AM:mode>3" > + [(set (match_operand:AM 0 "register_operand" "=r,r") > + (div:AM (match_operand:AM 1 "register_operand" " 0,0") > + (match_operand:AM 2 "reg_or_imm_operand" "r,I")))] > + "" > + "div<msuffix>\t%0,%2" > + [(set_attr "type" "<mtype>")]) > + > +(define_insn "udiv<AM:mode>3" > + [(set (match_operand:AM 0 "register_operand" "=r,r") > + (div:AM (match_operand:AM 1 "register_operand" " 0,0") > + (match_operand:AM 2 "reg_or_imm_operand" "r,I")))] > + "" > + "div<msuffix>\t%0,%2" > + [(set_attr "type" "<mtype>")]) div and udiv are two different operations. I don't see how we can use the same eBPF instruction for both. The rtl for udiv should also use the udiv rtx code.
> +;;; Modulus > +(define_insn "mod<AM:mode>3" > + [(set (match_operand:AM 0 "register_operand" "=r,r") > + (mod:AM (match_operand:AM 1 "register_operand" " 0,0") > + (match_operand:AM 2 "reg_or_imm_operand" "r,I")))] > + "" > + "mod<msuffix>\t%0,%2" > + [(set_attr "type" "<mtype>")]) > + > +(define_insn "umod<AM:mode>3" > + [(set (match_operand:AM 0 "register_operand" "=r,r") > + (mod:AM (match_operand:AM 1 "register_operand" " 0,0") > + (match_operand:AM 2 "reg_or_imm_operand" "r,I")))] > + "" > + "mod<msuffix>\t%0,%2" > + [(set_attr "type" "<mtype>")]) Same here, with umod for the rtx code. Oh dear the signed division... during development I just made both signed and unsigned flavors to use the same instructions, then forgot to change it. Why did I do that? Because eBPF does not provide instructions for doing _signed_ division, nor signed remainder: both `div' and `mod' perform unsigned arithmetic. clang/llvm ICEs whenever it finds signed division in a C program: $ clang -target bpf foo.c Error: Unsupport signed division for DAG: t17: i64 = sdiv t15, t16Please convert to unsigned div/mod. fatal error: error in backend: Cannot select: t17: i64 = sdiv t15, t16 For GCC I much prefer for the compiler to generate funcalls instead, to __divdi3/__divsi3/__moddi3/__modsi3 or the like, even if nothing is providing implementations for these functions (yet.) So I just defined the u{div,mod}MODE3 patterns in bpf.md (yes this time using the right rtl opcode :P) and removed the insns for signed operations. Thanks for noticing this!