Owen Anderson
6acf8c9125
Reapply r121905 (automatic synthesis of @llvm.sadd.with.overflow) with a fix for a bug that manifested itself
...
on the DragonEgg self-host bot. Unfortunately, the testcase is pretty messy and doesn't reduce well due to
interactions with other parts of InstCombine.
llvm-svn: 122072
2010-12-17 18:08:00 +00:00
Benjamin Kramer
39b30b18fa
SimplifyCFG: Ranges can be larger than 64 bits. Fixes Release-selfhost build.
...
llvm-svn: 122054
2010-12-17 10:48:14 +00:00
Chris Lattner
e92f8121d4
improve switch formation to handle small range
...
comparisons formed by comparisons. For example,
this:
void foo(unsigned x) {
if (x == 0 || x == 1 || x == 3 || x == 4 || x == 6)
bar();
}
compiles into:
_foo: ## @foo
## BB#0: ## %entry
cmpl $6, %edi
ja LBB0_2
## BB#1: ## %entry
movl %edi, %eax
movl $91, %ecx
btq %rax, %rcx
jb LBB0_3
instead of:
_foo: ## @foo
## BB#0: ## %entry
cmpl $2, %edi
jb LBB0_4
## BB#1: ## %switch.early.test
cmpl $6, %edi
ja LBB0_3
## BB#2: ## %switch.early.test
movl %edi, %eax
movl $88, %ecx
btq %rax, %rcx
jb LBB0_4
This catches a bunch of cases in GCC, which look like this:
%804 = load i32* @which_alternative, align 4, !tbaa !0
%805 = icmp ult i32 %804, 2
%806 = icmp eq i32 %804, 3
%or.cond121 = or i1 %805, %806
%807 = icmp eq i32 %804, 4
%or.cond124 = or i1 %or.cond121, %807
br i1 %or.cond124, label %.thread, label %808
turning this into a range comparison.
llvm-svn: 122045
2010-12-17 06:20:15 +00:00
Dan Gohman
f8949c3d1a
Revert r64460. strtol and friends cannot be marked readonly, even with
...
a null endptr argument, because they may write to errno.
This fixes a seflhost miscompile observed on Linux targets when TBAA
was enabled.
llvm-svn: 122014
2010-12-17 01:09:43 +00:00
Frits van Bommel
56dc4fc838
Fix a bug in the loop in JumpThreading::ProcessThreadableEdges() where it could falsely produce a MultipleDestSentinel value if the first predecessor ended with an 'indirectbr'. If that happened, it caused an unnecessary FindMostPopularDest() call.
...
This wasn't a correctness problem, but it broke the fast path for single-predecessor blocks.
llvm-svn: 121966
2010-12-16 12:16:00 +00:00
Duncan Sands
22de496ae3
Speculatively revert commit 121905 since it looks like it might have broken the
...
dragonegg self-host buildbot. Original commit message:
Add an InstCombine transform to recognize instances of manual overflow-safe addition
(performing the addition in a wider type and explicitly checking for overflow), and
fold them down to intrinsics. This currently only supports signed-addition, but could
be generalized if someone works out the magic constant formulas for other operations.
llvm-svn: 121965
2010-12-16 09:40:54 +00:00
Dan Gohman
e106936414
Make memcpyopt TBAA-aware.
...
llvm-svn: 121944
2010-12-16 02:51:19 +00:00
Dan Gohman
a2fd4f2e22
Preserve TBAA tags when doing load PRE.
...
llvm-svn: 121921
2010-12-15 23:53:55 +00:00
Owen Anderson
aefeb448a9
Add an InstCombine transform to recognize instances of manual overflow-safe addition
...
(performing the addition in a wider type and explicitly checking for overflow), and
fold them down to intrinsics. This currently only supports signed-addition, but could
be generalized if someone works out the magic constant formulas for other operations.
Fixes <rdar://problem/8558713>.
llvm-svn: 121905
2010-12-15 22:32:38 +00:00
Dan Gohman
295ba3ab26
Move Value::getUnderlyingObject to be a standalone
...
function so that it can live in Analysis instead of
VMCore.
llvm-svn: 121885
2010-12-15 20:02:24 +00:00
Duncan Sands
2699fb1072
Move Sub simplifications and additional Add simplifications out of
...
instcombine and into InstructionSimplify.
llvm-svn: 121861
2010-12-15 14:07:39 +00:00
Frits van Bommel
83b7c3773f
Teach jump threading to "look through" a select when the branch direction of a terminator depends on it.
...
When it sees a promising select it now tries to figure out whether the condition of the select is known in any of the predecessors and if so it maps the operands appropriately.
llvm-svn: 121859
2010-12-15 09:51:20 +00:00
Chris Lattner
1499119975
make qsort predicate more conformant by returning 0 for equal values.
...
llvm-svn: 121838
2010-12-15 04:52:41 +00:00
Owen Anderson
de42e1136e
Fix PR8790, another instance where unreachable code can cause instruction simplification to fail,
...
this case involve a select that simplifies to itself.
llvm-svn: 121817
2010-12-15 00:55:35 +00:00
Owen Anderson
df08ec80df
Cleanup trailing whitespace.
...
llvm-svn: 121816
2010-12-15 00:52:44 +00:00
Chris Lattner
c1aaf52608
- Insert new instructions before DomBlock's terminator,
...
which is simpler than finding a place to insert in BB.
- Don't perform the 'if condition hoisting' xform on certain
i1 PHIs, as it interferes with switch formation.
This re-fixes "example 7", without breaking the world hopefully.
llvm-svn: 121764
2010-12-14 08:46:09 +00:00
Chris Lattner
22d4dc5a4d
fix two significant issues with FoldTwoEntryPHINode:
...
first, it can kick in on blocks whose conditions have been
folded to a constant, even though one of the edges will be
trivially folded.
second, it doesn't clean up the "if diamond" that it just
eliminated away. This is a problem because other simplifycfg
xforms kick in depending on the order of block visitation,
causing pointless work.
llvm-svn: 121762
2010-12-14 08:01:53 +00:00
Chris Lattner
362f9a82c0
remove the instsimplify logic I added in r121754. It is apparently
...
breaking the selfhost builds, though I can't fathom how.
llvm-svn: 121761
2010-12-14 07:53:03 +00:00
Chris Lattner
c2e42269ae
clean up logic, convert std::set to SmallPtrSet, handle the case
...
when all 2-entry phis are simplified away.
llvm-svn: 121760
2010-12-14 07:41:39 +00:00
Chris Lattner
8e4194276b
tidy up a bit, move DEBUG down to when we commit to doing the transform so we
...
don't print it unless the xform happens.
llvm-svn: 121758
2010-12-14 07:23:10 +00:00
Chris Lattner
811462b2f4
use SimplifyInstruction instead of reimplementing part of it.
...
llvm-svn: 121757
2010-12-14 07:20:29 +00:00
Chris Lattner
e2400eb801
simplify GetIfCondition by using getSinglePredecessor.
...
llvm-svn: 121756
2010-12-14 07:15:21 +00:00
Chris Lattner
8ea88e66dd
use AddPredecessorToBlock in 3 places instead of a manual loop.
...
llvm-svn: 121755
2010-12-14 07:09:42 +00:00
Chris Lattner
a87ac36a54
make FoldTwoEntryPHINode use instsimplify a bit, make
...
GetIfCondition faster by avoiding pred_iterator. No
really interesting change.
llvm-svn: 121754
2010-12-14 07:00:00 +00:00
Chris Lattner
027d572664
remove the dead (and terrible) llvm::RemoveSuccessor function.
...
llvm-svn: 121753
2010-12-14 06:51:55 +00:00
Chris Lattner
d9436ab7d7
improve DEBUG's a bit, switch to eraseFromParent() to simplify
...
code a bit, switch from constant folding to instsimplify.
llvm-svn: 121751
2010-12-14 06:17:25 +00:00
Chris Lattner
093b5b256d
reapply my recent change that disables a piece of the switch formation
...
work, but fixes 400.perlbmk.
llvm-svn: 121749
2010-12-14 05:57:30 +00:00
Owen Anderson
5536134dc4
Fix recent buildbot breakage by pulling SimplifyCFG back to its state as of r121694, the most recent state
...
where I'm confident there were no crashes or miscompilations. XFAIL the test added since then for now.
llvm-svn: 121733
2010-12-13 23:49:28 +00:00
Chris Lattner
dcba81d96f
temporarily disable part of my previous patch, which causes an iterator invalidation issue, causing a crash on some versions of perlbmk.
...
llvm-svn: 121728
2010-12-13 23:02:19 +00:00
Chris Lattner
759d8aa712
add some DEBUG's.
...
llvm-svn: 121711
2010-12-13 19:55:30 +00:00
Benjamin Kramer
7f1cdac1e4
Fix sort predicate. qsort(3)'s predicate semantics differ from std::sort's. Fixes PR 8780.
...
llvm-svn: 121705
2010-12-13 18:20:38 +00:00
Chris Lattner
0368bf7457
reinstate my patch: the miscompile was caused by an inverted branch in the
...
'and' case.
llvm-svn: 121695
2010-12-13 08:12:19 +00:00
Chris Lattner
caad324345
Completely disable the optimization I added in r121680 until
...
I can track down a miscompile. This should bring the buildbots
back to life
llvm-svn: 121693
2010-12-13 07:41:29 +00:00
Chris Lattner
5ce3e42d80
Make simplifycfg reprocess newly formed "br (cond1 | cond2)" conditions
...
when simplifying, allowing them to be eagerly turned into switches. This
is the last step required to get "Example 7" from this blog post:
http://blog.regehr.org/archives/320
On X86, we now generate this machine code, which (to my eye) seems better
than the ICC generated code:
_crud: ## @crud
## BB#0: ## %entry
cmpb $33, %dil
jb LBB0_4
## BB#1: ## %switch.early.test
addb $-34, %dil
cmpb $58, %dil
ja LBB0_3
## BB#2: ## %switch.early.test
movzbl %dil, %eax
movabsq $288230376537592865, %rcx ## imm = 0x400000017001421
btq %rax, %rcx
jb LBB0_4
LBB0_3: ## %lor.rhs
xorl %eax, %eax
ret
LBB0_4: ## %lor.end
movl $1, %eax
ret
llvm-svn: 121690
2010-12-13 07:00:06 +00:00
Chris Lattner
20b9e84c7e
make this logic a bit simpler.
...
llvm-svn: 121689
2010-12-13 06:36:51 +00:00
Chris Lattner
74d917e19d
split all the guts of SimplifyCFGOpt::run out into one function
...
per terminator kind.
llvm-svn: 121688
2010-12-13 06:25:44 +00:00
Chris Lattner
ea15ce73be
fix a bug in r121680 that upset the various buildbots.
...
llvm-svn: 121687
2010-12-13 05:34:18 +00:00
Chris Lattner
1eb2e235c8
refactor the speculative execution logic to be factored into the cond branch code instead of
...
doing a cfg search for every block simplified.
llvm-svn: 121686
2010-12-13 05:26:52 +00:00
Chris Lattner
4b9e3a31b0
simplify a bunch of code.
...
llvm-svn: 121685
2010-12-13 05:20:28 +00:00
Chris Lattner
d79dd057bf
move HoistThenElseCodeToIf up to a more logical and efficient-to-handle place.
...
llvm-svn: 121684
2010-12-13 05:15:29 +00:00
Chris Lattner
80f8577d74
move 'MergeBlocksIntoPredecessor' call earlier. Use
...
getSinglePredecessor to simplify code.
llvm-svn: 121683
2010-12-13 05:10:48 +00:00
Chris Lattner
7ad8e06c3b
factor new code out to a SimplifyBranchOnICmpChain helper function.
...
llvm-svn: 121681
2010-12-13 05:03:41 +00:00
Chris Lattner
5cbbcc56ad
enhance the "change or icmp's into switch" xform to handle one value in an
...
'or sequence' that it doesn't understand. This allows us to optimize
something insane like this:
int crud (unsigned char c, unsigned x)
{
if(((((((((( (int) c <= 32 ||
(int) c == 46) || (int) c == 44)
|| (int) c == 58) || (int) c == 59) || (int) c == 60)
|| (int) c == 62) || (int) c == 34) || (int) c == 92)
|| (int) c == 39) != 0)
foo();
}
into:
define i32 @crud(i8 zeroext %c, i32 %x) nounwind ssp noredzone {
entry:
%cmp = icmp ult i8 %c, 33
br i1 %cmp, label %if.then, label %switch.early.test
switch.early.test: ; preds = %entry
switch i8 %c, label %if.end [
i8 39, label %if.then
i8 44, label %if.then
i8 58, label %if.then
i8 59, label %if.then
i8 60, label %if.then
i8 62, label %if.then
i8 46, label %if.then
i8 92, label %if.then
i8 34, label %if.then
]
by pulling the < comparison out ahead of the newly formed switch.
llvm-svn: 121680
2010-12-13 04:50:38 +00:00
Chris Lattner
f6be61e969
merge two very similar functions into one that has a bool argument.
...
llvm-svn: 121678
2010-12-13 04:26:26 +00:00
Chris Lattner
003b79e2d3
don't bother handling non-canonical icmp's
...
llvm-svn: 121676
2010-12-13 04:18:32 +00:00
Chris Lattner
9bd0b12342
inline a function, making the result much simpler.
...
llvm-svn: 121675
2010-12-13 04:15:19 +00:00
Chris Lattner
25b642edfd
Fix my previous patch to handle a degenerate case that the llvm-gcc
...
bootstrap buildbot tripped over.
llvm-svn: 121674
2010-12-13 03:43:57 +00:00
Chris Lattner
9b089512e9
convert some methods to be static functions
...
llvm-svn: 121673
2010-12-13 03:30:12 +00:00
Chris Lattner
46cc5158bb
zap two more std::sorts.
...
llvm-svn: 121672
2010-12-13 03:24:30 +00:00
Chris Lattner
a21c02e807
fix a fairly serious oversight with switch formation from
...
or'd conditions. Previously we'd compile something like this:
int crud (unsigned char c) {
return c == 62 || c == 34 || c == 92;
}
into:
switch i8 %c, label %lor.rhs [
i8 62, label %lor.end
i8 34, label %lor.end
]
lor.rhs: ; preds = %entry
%cmp8 = icmp eq i8 %c, 92
br label %lor.end
lor.end: ; preds = %entry, %entry, %lor.rhs
%0 = phi i1 [ true, %entry ], [ %cmp8, %lor.rhs ], [ true, %entry ]
%lor.ext = zext i1 %0 to i32
ret i32 %lor.ext
which failed to merge the compare-with-92 into the switch. With this patch
we simplify this all the way to:
switch i8 %c, label %lor.rhs [
i8 62, label %lor.end
i8 34, label %lor.end
i8 92, label %lor.end
]
lor.rhs: ; preds = %entry
br label %lor.end
lor.end: ; preds = %entry, %entry, %entry, %lor.rhs
%0 = phi i1 [ true, %entry ], [ false, %lor.rhs ], [ true, %entry ], [ true, %entry ]
%lor.ext = zext i1 %0 to i32
ret i32 %lor.ext
which is much better for codegen's switch lowering stuff. This kicks in 33 times
on 176.gcc (for example) cutting 103 instructions off the generated code.
llvm-svn: 121671
2010-12-13 03:18:54 +00:00