[Bug 1248606] Re: Compiler optimisation affects reading of flag in thread

Throctukes 1248606 at bugs.launchpad.net
Wed Nov 6 17:34:14 UTC 2013


With that simpler example I can get it to lock up using -O and manually
turning off all the flags it sets except -finline-atomics, -ftree-loop-
im and -ftree-loop-optimize. Turning either of the tree optimisations
off causes it to work for me; turning inline-atomics off prevents
compilation. Experimenting with variations of this causes different
combinations of flags to be required to cause the problem but just
setting -O3 always causes the issue, and the flags involved with the
problem always seem to be to do with tree optimisations.

I think what's happening is the compiler is deciding that the flags have
been set before it hits the loop and then can't be changed inside the
loop so there's no need to re-evaluate them (that seems to be what the
disassembly is doing in the broken case, too). That would be correct if
it weren't for the threads - they mean that it *does* need to re-
evalutate the flags.

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-4.8 in Ubuntu.
https://bugs.launchpad.net/bugs/1248606

Title:
  Compiler optimisation affects reading of flag in thread

Status in “gcc-4.8” package in Ubuntu:
  Confirmed

Bug description:
  We have a thread pool implementation (from before std::async became
  available). But the update from gcc 4.7 to 4.8 has broken the
  implementation. We have since solved it but the way it was broken
  suggests a bug in the compiler optimisation.

  I have attached a fully working example which can be compiled as follows:
  g++ -o gcc-thread-bug gcc-thread-bug.cpp -O3 -std=c++11 -pthread -Wl,--no-as-needed

  When run the loop will get stuck checking the status of the threads.

  If the line setting the flag to false first is uncommented then it
  works (even though that should have no effect on the logic of the
  loop). If the optimisations (-O3) are disabled then it works.

  Our implementation has had heavy use for some time now and it is only
  the switch to gcc-4.8 that seems to have stopped it working.

  We've narrowed it down to the following optimisations:

  -ftree-pre -ftree-vrp -O but disable EVERY FLAG that -O sets except
  for: -ftree-sra -ftree-dce -ftree-ch -ftree-ccp -finline -finline-
  atomics -fira-hoist-pressure -ftree-loop-im -ftree-loop-optimize

  i.e.:
  g++ -o gcc-thread-bug gcc-thread-bug.cpp -std=c++11 -pthread -Wl,--no-as-needed -O -ftree-pre -ftree-vrp -fno-auto-inc-dec -fno-compare-elim -fno-cprop-registers -fno-dce -fno-defer-pop -fno-delayed-branch -fno-dse -fno-guess-branch-probability -fno-if-conversion2 -fno-if-conversion -fno-ipa-pure-const -fno-ipa-profile -fno-ipa-reference -fno-merge-constants -fno-split-wide-types -fno-tree-bit-ccp -fno-tree-builtin-call-dce -ftree-ccp -ftree-ch -fno-tree-copyrename -ftree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-forwprop -fno-tree-fre -fno-tree-phiprop -fno-tree-slsr -ftree-sra -fno-tree-pta -fno-tree-ter -fno-unit-at-a-time -fno-combine-stack-adjustments -fno-forward-propagate -fno-inline-functions-called-once -fno-shrink-wrap -fno-tree-builtin-call-dce -fno-tree-copy-prop -fno-tree-sink -fno-aggressive-loop-optimizations -fno-asynchronous-unwind-tables -fno-branch-count-reg -fno-common -fno-delete-null-pointer-checks -fno-early-inlining -fno-gcse-lm -fno-ivopts -fno-jump-tables -fno-math-errno -fno-move-loop-invariants -fno-peephole -fno-prefetch-loop-arrays -fno-rename-registers -fno-rtti -fno-sched-critical-path-heuristic -fno-sched-dep-count-heuristic -fno-sched-group-heuristic -fno-sched-interblock -fno-sched-last-insn-heuristic -fno-sched-rank-heuristic -fno-sched-spec -fno-sched-spec-insn-heuristic -fno-sched-stalled-insns-dep -fno-short-enums -fno-signed-zeros -fno-split-ivs-in-unroller -fno-toplevel-reorder -fno-trapping-math -fno-tree-coalesce-vars -fno-tree-cselim -fno-tree-loop-if-convert -fno-tree-loop-ivcanon -fno-tree-reassoc -fno-tree-scev-cprop -fno-tree-slp-vectorize -fno-tree-vect-loop-version -fno-var-tracking -fno-var-tracking-assignments -fno-web

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-4.8/+bug/1248606/+subscriptions



More information about the foundations-bugs mailing list