{"action":"created","issue":{"url":"https://api.github.com/repos/BeRo1985/flre/issues/49","repository_url":"https://api.github.com/repos/BeRo1985/flre","labels_url":"https://api.github.com/repos/BeRo1985/flre/issues/49/labels{/name}","comments_url":"https://api.github.com/repos/BeRo1985/flre/issues/49/comments","events_url":"https://api.github.com/repos/BeRo1985/flre/issues/49/events","html_url":"https://github.com/BeRo1985/flre/issues/49","id":347743841,"node_id":"MDU6SXNzdWUzNDc3NDM4NDE=","number":49,"title":"FLRE gives wrong output at optimization levels above O1 with x64 FPC 3.1.1 on Windows","user":{"login":"Akira13641","id":11223712,"node_id":"MDQ6VXNlcjExMjIzNzEy","avatar_url":"https://avatars0.githubusercontent.com/u/11223712?v=4","gravatar_id":"","url":"https://api.github.com/users/Akira13641","html_url":"https://github.com/Akira13641","followers_url":"https://api.github.com/users/Akira13641/followers","following_url":"https://api.github.com/users/Akira13641/following{/other_user}","gists_url":"https://api.github.com/users/Akira13641/gists{/gist_id}","starred_url":"https://api.github.com/users/Akira13641/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Akira13641/subscriptions","organizations_url":"https://api.github.com/users/Akira13641/orgs","repos_url":"https://api.github.com/users/Akira13641/repos","events_url":"https://api.github.com/users/Akira13641/events{/privacy}","received_events_url":"https://api.github.com/users/Akira13641/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-08-06T00:13:48Z","updated_at":"2018-08-06T04:01:48Z","closed_at":null,"author_association":"NONE","body":"Hi. I'm trying to use FLRE to make a better Free Pascal entry for the Regex Redux benchmark on the [Benchmarks Game website.](https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/regexredux.html)\r\n\r\nI have a version that works pretty well, but I cannot set the optimization level above 1 without getting invalid output. The correct output that I get at -O1, that matches all the other entries on the website, is this:  \r\n\r\n```\r\n(agggtaaa|tttaccct) 356\r\n([cgt]gggtaaa|tttaccc[acg]) 1250\r\n(a[act]ggtaaa|tttacc[agt]t) 4252\r\n(ag[act]gtaaa|tttac[agt]ct) 2894\r\n(agg[act]taaa|ttta[agt]cct) 5435\r\n(aggg[acg]aaa|ttt[cgt]ccct) 1537\r\n(agggt[cgt]aa|tt[acg]accct) 1431\r\n(agggta[cgt]a|t[acg]taccct) 1608\r\n(agggtaa[cgt]|[acg]ttaccct) 2178\r\n50833411\r\n50000000\r\n27388361\r\n\r\n```\r\n\r\nWhen I go above -O1 though, I get this instead:\r\n\r\n```\r\n(agggtaaa|tttaccct) 320\r\n([cgt]gggtaaa|tttaccc[acg]) 1143\r\n(a[act]ggtaaa|tttacc[agt]t) 3676\r\n(ag[act]gtaaa|tttac[agt]ct) 2565\r\n(agg[act]taaa|ttta[agt]cct) 4736\r\n(aggg[acg]aaa|ttt[cgt]ccct) 1359\r\n(agggt[cgt]aa|tt[acg]accct) 1359\r\n(agggta[cgt]a|t[acg]taccct) 1393\r\n(agggtaa[cgt]|[acg]ttaccct) 1965\r\n50833411\r\n29\r\n27930151\r\n```\r\n\r\nwhich is wrong. Here's my code so far:\r\n\r\n```\r\nprogram RegexRedux;\r\n\r\n{$mode ObjFPC}{$H+}{$J-}\r\n\r\nuses\r\n  JMem, //this is a modified version of CMem I made that uses Jemalloc instead, but you can use CMem itself too\r\n  SysUtils,\r\n  Classes,\r\n  MTProcs,\r\n  BeRoFileMappedStream,\r\n  FLRE;\r\n\r\nconst\r\n  Patterns: array[0..8] of TFLRERawByteString = (\r\n    '(agggtaaa|tttaccct)', '([cgt]gggtaaa|tttaccc[acg])',\r\n    '(a[act]ggtaaa|tttacc[agt]t)', '(ag[act]gtaaa|tttac[agt]ct)',\r\n    '(agg[act]taaa|ttta[agt]cct)', '(aggg[acg]aaa|ttt[cgt]ccct)',\r\n    '(agggt[cgt]aa|tt[acg]accct)', '(agggta[cgt]a|t[acg]taccct)',\r\n    '(agggtaa[cgt]|[acg]ttaccct)');\r\n  Substitutions: array[0..4] of TFLRERawByteString = (\r\n    '(tHa[Nt])',\r\n    '(aND|caN|Ha[DS]|WaS)',\r\n    '(a[NSt]|BY)',\r\n    '(<[^>]*>)',\r\n    '(\\|[^|][^|]*\\|)');\r\n  Replacements: array[0..4] of TFLRERawByteString = (\r\n    '<4>', '<3>', '<2>', '|', '-');\r\n\r\nvar\r\n  Counts: array[0..8] of Integer;\r\n  Statuses: array[0..4] of Boolean;\r\n  LengthA, LengthB, LengthC: Integer;\r\n  InputText: TFLRERawByteString;\r\n\r\n  procedure Split(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem);\r\n  var\r\n    Captures: TFLREMultiCaptures;\r\n  begin\r\n    with TFLRE.Create(Patterns[Index]) do\r\n    begin\r\n      MatchAll(InputText, Captures);\r\n      Counts[Index] := Length(Captures);\r\n      Free;\r\n    end;\r\n  end;\r\n\r\n  procedure Substitute(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem);\r\n  var\r\n    Reg: TFLRE; //has to be a named variable for this one or it segfaults, don't know why\r\n  begin\r\n    Reg := TFLRE.Create(Substitutions[Index]);\r\n    if Index <> 0 then\r\n      while not Statuses[Index - 1] do ;\r\n    InputText := Reg.Replace(InputText, Replacements[Index]);\r\n    Statuses[Index] := True;\r\n    Reg.Free;\r\n  end;\r\n\r\nvar\r\n  I: Integer;\r\n  Stream: TBeRoFileMappedStream;\r\n  Regex: TFLRE;\r\nbegin\r\n  Stream := TBeRoFileMappedStream.Create('input5000000.txt', fmOpenRead);\r\n  SetLength(InputText, Stream.Size);\r\n  Stream.Read(InputText[1], Stream.Size);\r\n  LengthA := Length(InputText);\r\n  Stream.Free;\r\n  Regex := TFLRE.Create('(>.*|\\n)');\r\n  InputText := Regex.Replace(InputText, '');\r\n  LengthB := Length(InputText);\r\n  Regex.Free;\r\n  ProcThreadPool.DoParallel(@Split, 0, 8);\r\n  ProcThreadPool.DoParallel(@Substitute, 0, 4);\r\n  LengthC := Length(InputText);\r\n  for I := 0 to 8 do\r\n    Write(Patterns[I], #32, Counts[I], #10);\r\n  Write(LengthA, #10, LengthB, #10, LengthC, #10);\r\nend.\r\n```\r\n\r\nAny suggestions for what might be causing this?"},"comment":{"url":"https://api.github.com/repos/BeRo1985/flre/issues/comments/410582622","html_url":"https://github.com/BeRo1985/flre/issues/49#issuecomment-410582622","issue_url":"https://api.github.com/repos/BeRo1985/flre/issues/49","id":410582622,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDU4MjYyMg==","user":{"login":"BeRo1985","id":428863,"node_id":"MDQ6VXNlcjQyODg2Mw==","avatar_url":"https://avatars0.githubusercontent.com/u/428863?v=4","gravatar_id":"","url":"https://api.github.com/users/BeRo1985","html_url":"https://github.com/BeRo1985","followers_url":"https://api.github.com/users/BeRo1985/followers","following_url":"https://api.github.com/users/BeRo1985/following{/other_user}","gists_url":"https://api.github.com/users/BeRo1985/gists{/gist_id}","starred_url":"https://api.github.com/users/BeRo1985/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BeRo1985/subscriptions","organizations_url":"https://api.github.com/users/BeRo1985/orgs","repos_url":"https://api.github.com/users/BeRo1985/repos","events_url":"https://api.github.com/users/BeRo1985/events{/privacy}","received_events_url":"https://api.github.com/users/BeRo1985/received_events","type":"User","site_admin":false},"created_at":"2018-08-06T04:01:48Z","updated_at":"2018-08-06T04:01:48Z","author_association":"OWNER","body":"And do you compile it as x86-32 or x86-64 build, and on which target operating system (due to the possible different OS ABIs)?"}}
{"actor":{"display_login":"BeRo1985"}}