This is an archive of the discontinued LLVM Phabricator instance.

[ConstraintElim] Add option to limit number of rows tracked in system.
ClosedPublic

Authored by fhahn on Jan 3 2023, 2:31 PM.

Details

Summary

Once the constraint system grows too large in terms of number of rows,
queries can become very slow. This patch adds a new option to limit the
number of rows tracked.

The python script below can be used to generate worst-case IR with a
chain of conditional branches with N branches.

With this limit, we get the following runtimes:

  • python3 generate.py 100: 0.1s
  • python3 generate.py 1000: 2s
  • python3 generate.py 10000: 4s

Without the limit, the case with 1000 chained conditions takes 20+
seconds.

generate.py:

import sys

N = int(sys.argv[1])

args = []
checks = []

for i in range(0, N):
    args.append('i32 %l{}'.format(i))
    checks.append("""
bb{0}:
  %c{0} = icmp uge i32 %l{0}, 100
  br i1 %c{0}, label %bb{1}, label %exit
""".format(i, i+1))

print("""
define i1 @foo({0}) {{
{1}

bb{2}:
  %c{2} = icmp uge i32 %l0, 100
  ret i1 %c{2}

exit:
  ret i1 false
}}
""".format(' ,'.join(args), '\n'.join(checks), N))

Diff Detail

Event Timeline

fhahn created this revision.Jan 3 2023, 2:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 2:31 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
fhahn requested review of this revision.Jan 3 2023, 2:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 2:31 PM
nikic accepted this revision.Jan 4 2023, 1:03 AM

LGTM

This revision is now accepted and ready to land.Jan 4 2023, 1:03 AM
fhahn updated this revision to Diff 486226.Jan 4 2023, 3:22 AM

Rebase before landing.