Fix a problem in the new upsert implemention, discovered by OSSFuzz.

FossilOrigin-Name: b6d5ea59fe83716f464e408b7eef0310c6d30b3493e3f966362db2e30b36e821
diff --git a/src/insert.c b/src/insert.c
index 2a6d74d..e522d46 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -1471,15 +1471,6 @@
       onError = OE_Abort;
     }
 
-    if( isUpdate ){
-      /* pkChng!=0 does not mean that the rowid has changed, only that
-      ** it might have changed.  Skip the conflict logic below if the rowid
-      ** is unchanged. */
-      sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
-      sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
-      VdbeCoverage(v);
-    }
-
     /* figure out whether or not upsert applies in this case */
     if( pUpsert && pUpsert->pUpsertIdx==0 ){
       if( pUpsert->pUpsertSet==0 ){
@@ -1506,6 +1497,15 @@
       sAddr.ipkTop = sqlite3VdbeAddOp0(v, OP_Goto)+1;
     }
 
+    if( isUpdate ){
+      /* pkChng!=0 does not mean that the rowid has changed, only that
+      ** it might have changed.  Skip the conflict logic below if the rowid
+      ** is unchanged. */
+      sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
+      sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
+      VdbeCoverage(v);
+    }
+
     /* Check to see if the new rowid already exists in the table.  Skip
     ** the following conflict logic if it does not. */
     VdbeNoopComment((v, "uniqueness check for ROWID"));