Commit Graph

27 Commits

Author SHA1 Message Date
Nadav Rotem
fbfbc2afbf Fix a bug in a code that assumes that builtins must have two operands.
This commits moves the code that accesses the operands after the point where
we identify the builtins and know they have two operands.

rdar://20711757

Swift SVN r27810
2015-04-27 19:20:26 +00:00
Nadav Rotem
240ff14db1 Split DominanceAnalysis into Dom and PDom using FunctionAnalysisBase.
This commit splits DominanceAnalysis into two analysis (Dom and PDom) that
can be cached and invalidates using the common FunctionAnalysisBase interface
independent of one another.

Swift SVN r26643
2015-03-27 20:54:28 +00:00
Nadav Rotem
28042c7030 Fix a bug in the comparison of -INT_MIN values. The result of abs() is an unsinged number that can represent the complete input range. We need to use unsigned operations on the result of abs().
Swift SVN r26594
2015-03-26 15:15:36 +00:00
Nadav Rotem
7aa6a27a22 Abbreviate the constraint argument names to match the comments. NFC.
Swift SVN r26593
2015-03-26 15:15:18 +00:00
Nadav Rotem
e320b2466e Fix a bug in the code that removes overflows from signed multiplication.
The overflow check for X * 1 does not guard the check for X * -1
because X could be MIN_INT, and MIN_INT*-1 overflows. In the new code
we check that the new multiplier is smaller (not smaller or equal).

Swift SVN r26553
2015-03-25 20:42:24 +00:00
Nadav Rotem
13c9f22f73 Fix a bug in the code that removes redundant overflow checks in signed multiplication.
Previously we were removing overflow checks if a previous (or future) check
used a smaller multiplier. However, this logic is incorrect for signed integers
because it does not consider underflows (example, x * 10 vs. x * -100000).

The code now checks that the multiplier that's dominated by another check is
closer or equal to zero (the absolute value is smaller or equal to the
guarding multiplier).

Swift SVN r26550
2015-03-25 19:47:31 +00:00
Nadav Rotem
dc01d61c72 [overflow] Teach the overflow optimizations to get rid of multiplication overflow checks.
Use the knowledge of previous (or future) overflow checks to remove multiplication by smaller values.
For example:
  x * 100
  x * 10 // can remove this overflow checks.

Swift SVN r26543
2015-03-25 17:01:26 +00:00
Nadav Rotem
d78b376d07 [passes] Replace the old invalidation lattice with a new invalidation scheme.
The old invalidation lattice was incorrect because changes to control flow could cause changes to the
call graph, so we've decided to change the way passes invalidate analysis.  In the new scheme, the lattice
is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches.
Now, passes report which traits they preserve, which is the opposite of the previous implementation where
passes needed to report what they invalidate.

Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some
of the code in a following commit.

Swift SVN r26449
2015-03-23 21:18:58 +00:00
Nadav Rotem
550de8df2e [overflow] eliminate subtraction based on equality constraints.
Swift SVN r26192
2015-03-16 22:12:29 +00:00
Nadav Rotem
ced25883a0 [overflow] Fix a bug in the comparison of literals of with different bitwidths
Swift SVN r26060
2015-03-12 20:36:53 +00:00
Nadav Rotem
f3daf61fdd Wrap the line to 80 col.
Swift SVN r26053
2015-03-12 19:00:45 +00:00
Nadav Rotem
1336b53a08 Bugfix. When scanning the basic block in reverse skip the 'end' because it is not a valid instruction.
Swift SVN r26042
2015-03-12 08:11:25 +00:00
Nadav Rotem
063ebee83a Fix a typo
Swift SVN r26039
2015-03-12 07:27:44 +00:00
Nadav Rotem
95278e774e [overflow] Scan the code in reverse and allow future (stronger) overflow checks to replace early overflow checks.
func reverse(x : Int) {
  x + 1 // remove
  x + 2 // remove
  x + 3 // remove
  x + 4 // remove
  x + 5 // keep
}

Swift SVN r26038
2015-03-12 07:18:53 +00:00
Nadav Rotem
15ba646870 [overflow] Refactor the code that removes the dead cond_fail instructions. NFC.
Swift SVN r26037
2015-03-12 07:18:52 +00:00
Nadav Rotem
8572586415 [overflow] Rename a method and document it.
Swift SVN r26036
2015-03-12 07:18:50 +00:00
Nadav Rotem
3dd40e5c42 Add a label to the llvm_unreachable. The build fails on some configurations without one.
Swift SVN r26019
2015-03-12 01:11:59 +00:00
Nadav Rotem
98a35d5ffc [overflow] Remove signed and unsigned overflow checks for X+1 and X-1 if X is smaller/greater than some other number.
If X is known to be smaller than some other number then we can add a 1 to X.
If X is known to be grater than some other number then we can subtract 1 from X.

func add1_signed_branch(x : Int, y : Int) {
  if (x < y) {
    sink(x + 1) // remove
    sink(x + 2) // keep
  }
}

Swift SVN r26016
2015-03-12 00:55:20 +00:00
Nadav Rotem
099d5d4cd2 [overflow] Remove signed and unsinged overflow checks on addition of a stronger check was executed before the current one.
func unsigned_add_previous_traps(x : UInt) {
  sink(x + 9)  // keep (this is the first overflow check)
  sink(x + 2)  // remove
  sink(x + 3)  // remove
  sink(x + 5)  // remove
  sink(x + 10) // keep (this check is not guarded by the first check)
  sink(x + 5)  // remove
}

Swift SVN r26015
2015-03-12 00:55:18 +00:00
Nadav Rotem
15aa317302 [overflow] Remove signed and unsigned overflow checks if we executed a stronger trap before the current one.
func foo(x : Int) {
  sink(x - 9)  // keep (this is the first overflow check)
  sink(x - 2)  // remove
  sink(x - 3)  // remove
  sink(x - 5)  // remove
  sink(x - 10) // keep (not guarded by the first overflow check)
  sink(x - 5)  // remove
}

Swift SVN r26013
2015-03-12 00:55:17 +00:00
Nadav Rotem
bf3047a292 [overflow] Also optimize *unsigned* sub that are guarded by branches.
Swift SVN r26012
2015-03-12 00:55:16 +00:00
Nadav Rotem
6274423a77 [overflow] Add code to remove signed sub overflow checks under a branch:
func sub_signed_branch_cond(x : Int) {
  if (x < 2) {
    return
  }
  sink(x - 1) // remove
  sink(x - 2) // remove
  sink(x - 3) // keep
}

func sub_signed_branch_cond2(x : Int) {
  if (x >= 2) {
    sink(x - 1) // remove
    sink(x - 2) // remove
    sink(x - 3) // keep
  }
}

Swift SVN r26011
2015-03-12 00:55:15 +00:00
Nadav Rotem
c0124c0b42 [overflow] Scan the Constraint list and try to remove the condfail.
Swift SVN r26010
2015-03-12 00:55:13 +00:00
Nadav Rotem
8ecf1511a3 [overflow] Add helper functions to evaluate the numeric relations between sil values.
Swift SVN r26009
2015-03-12 00:55:12 +00:00
Nadav Rotem
cdfac4bfee [overflow] Scan the function body and collect overflow constraints.
Swift SVN r26008
2015-03-12 00:55:12 +00:00
Nadav Rotem
069f8eaafa [overflow] Add a new struct: Constraint - to represent a range constraint in a part of the function.
Swift SVN r26007
2015-03-12 00:55:11 +00:00
Nadav Rotem
5d08db87ec [overflow checks] Add a new (empty) pass to remove overflow checks
Swift SVN r26006
2015-03-12 00:55:06 +00:00