@@ -82,10 +82,15 @@ (define_mode_attr msuffix [(SI "32") (DI "")])
;;;; NOPs
+;; The Linux kernel verifier performs some optimizations that rely on
+;; nop instructions to be encoded as `ja 0', i.e. a jump to offset 0,
+;; which actually means to jump to the next instruction, since in BPF
+;; offsets are expressed in 64-bit words _minus one_.
+
(define_insn "nop"
[(const_int 0)]
""
- "mov\t%%r0,%%r0"
+ "ja\t0"
[(set_attr "type" "alu")])
;;;; Arithmetic/Logical
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 --patchable-function-entry=2,1" } */
+
+/* The purpose of this test is to make sure the right instruction is
+ generated for NOPs. See bpf.md for a description on why this is
+ important. */
+
+int
+foo ()
+{
+ return 0;
+}
+
+/* { dg-final { scan-assembler "foo:\n\t*ja\t0" } } */