Benjamin Kramer
e5f49c4ff2
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
d14b0f1db7
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
Chris Lattner
7499b452c1
- 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
335f0e4ad4
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
f130661688
fix yet anohter broken line
...
llvm-svn: 121750
2010-12-14 06:09:07 +00:00
Chris Lattner
5a9d59d918
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
3e5648896e
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
a6e5d5694a
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
Benjamin Kramer
1e155ab7e1
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
fb836f8c1a
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
79db357d80
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
fbeb55844b
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
cb570f87e5
fix a bug in r121680 that upset the various buildbots.
...
llvm-svn: 121687
2010-12-13 05:34:18 +00:00
Chris Lattner
bc9e6d9dbe
make these tests a bit less fragile
...
llvm-svn: 121682
2010-12-13 05:10:30 +00:00
Chris Lattner
a442f24a36
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
a737721d14
merge two tests
...
llvm-svn: 121679
2010-12-13 04:45:56 +00:00
Chris Lattner
62cc76e9cc
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
d9bacc088a
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
Frits van Bommel
8fb69ee805
Teach SimplifyCFG to turn
...
(indirectbr (select cond, blockaddress(@fn, BlockA),
blockaddress(@fn, BlockB)))
into
(br cond, BlockA, BlockB).
llvm-svn: 120943
2010-12-05 18:29:03 +00:00
Dan Gohman
a826a88755
Factor out Instruction::isSafeToSpeculativelyExecute's code for
...
testing for dereferenceable pointers into a helper function,
isDereferenceablePointer. Teach it how to reason about GEPs
with simple non-zero indices.
Also eliminate ArgumentPromtion's IsAlwaysValidPointer,
which didn't check for weak externals or out of range gep
indices.
llvm-svn: 118840
2010-11-11 21:23:25 +00:00
Duncan Sands
31c803b2ba
Fix PR8445: a block with no predecessors may be the entry block, in which case
...
it isn't unreachable and should not be zapped. The check for the entry block
was missing in one case: a block containing a unwind instruction. While there,
do some small cleanups: "M" is not a great name for a Function* (it would be
more appropriate for a Module*), change it to "Fn"; use Fn in more places.
llvm-svn: 117224
2010-10-24 12:23:30 +00:00
Duncan Sands
68c30907cc
Correct bogus module triple specifications.
...
llvm-svn: 112469
2010-08-30 10:48:29 +00:00
Dan Gohman
250b754428
Instead, teach SimplifyCFG to trim non-address-taken blocks from
...
indirectbr destination lists.
llvm-svn: 111122
2010-08-16 14:41:14 +00:00
Dan Gohman
4a63fad976
Teach SimplifyCFG how to simplify indirectbr instructions.
...
- Eliminate redundant successors.
- Convert an indirectbr with one successor into a direct branch.
Also, generalize SimplifyCFG to be able to be run on a function entry block.
It knows quite a few simplifications which are applicable to the entry
block, and it only needs a few checks to avoid trouble with the entry block.
llvm-svn: 111060
2010-08-14 00:29:42 +00:00
Benjamin Kramer
6e42d53cb3
Test case for r105914.
...
llvm-svn: 105915
2010-06-13 16:16:54 +00:00
Chris Lattner
84d4618659
make simplifycfg insert an llvm.trap before the 'unreachable' it introduces
...
when it detects undefined behavior. llvm.trap generally codegens into some
thing really small (e.g. a 2 byte ud2 instruction on x86) and debugging this
sort of thing is "nontrivial". For example, we now compile:
void foo() { *(int*)0 = 42; }
into:
_foo:
pushl %ebp
movl %esp, %ebp
ud2
Some may even claim that this is a security hole, though that seems dubious
to me. This addresses rdar://7958343 - Optimizing away null dereference
potentially allows arbitrary code execution
llvm-svn: 103356
2010-05-08 22:15:59 +00:00
Gabor Greif
6882a5eea1
testcase for r99914, provided by baldrick!
...
llvm-svn: 100043
2010-03-31 20:37:13 +00:00
Dan Gohman
6f34abd092
Floating-point add, sub, and mul are now spelled fadd, fsub, and fmul,
...
respectively.
llvm-svn: 97531
2010-03-02 01:11:08 +00:00
Jakob Stoklund Olesen
916f48a054
Teach SimplifyCFG about magic pointer constants.
...
Weird code sometimes uses pointer constants other than null. This patch
teaches SimplifyCFG to build switch instructions in those cases.
Code like this:
void f(const char *x) {
if (!x)
puts("null");
else if ((uintptr_t)x == 1)
puts("one");
else if (x == (char*)2 || x == (char*)3)
puts("two");
else if ((intptr_t)x == 4)
puts("four");
else
puts(x);
}
Now becomes a switch:
define void @f(i8* %x) nounwind ssp {
entry:
%magicptr23 = ptrtoint i8* %x to i64 ; <i64> [#uses=1]
switch i64 %magicptr23, label %if.else16 [
i64 0, label %if.then
i64 1, label %if.then2
i64 2, label %if.then9
i64 3, label %if.then9
i64 4, label %if.then14
]
Note that LLVM's own DenseMap uses magic pointers.
llvm-svn: 95439
2010-02-05 22:03:18 +00:00
Dan Gohman
fb4193625a
Delete useless trailing semicolons.
...
llvm-svn: 92740
2010-01-05 17:55:26 +00:00
Chris Lattner
c5c08899e4
fix two bogus tests that the asmparser now rejects.
...
llvm-svn: 92303
2009-12-30 05:54:51 +00:00
Chris Lattner
f21a220bcd
Implement PR5795 by merging duplicated return blocks. This could go further
...
by merging all returns in a function into a single one, but simplifycfg
currently likes to duplicate the return (an unfortunate choice!)
llvm-svn: 91890
2009-12-22 06:07:30 +00:00
Chris Lattner
2b297ed9ee
convert to filecheck
...
llvm-svn: 91889
2009-12-22 06:04:26 +00:00
Dan Gohman
1f31f6e265
Optimize test more.
...
llvm-svn: 86714
2009-11-10 21:02:18 +00:00
Chris Lattner
17529ac0c5
optimize test
...
llvm-svn: 86672
2009-11-10 07:44:36 +00:00
Dan Gohman
2d02ff8cbb
Revert r85667. LoopUnroll currently can't call utility functions which
...
auto-update the DominatorTree because it doesn't keep the DominatorTree
current while it works.
llvm-svn: 85670
2009-10-31 17:33:01 +00:00
Dan Gohman
041e2dbad1
Merge the enhancements from LoopUnroll's FoldBlockIntoPredecessor into
...
MergeBlockIntoPredecessor. This makes SimplifyCFG slightly more aggressive,
and makes it unnecessary for LoopUnroll to have its own copy of this code.
llvm-svn: 85667
2009-10-31 16:08:00 +00:00
Dan Gohman
56998cdc5b
Add a testcase for the recent duplicate PHI elimination changes.
...
llvm-svn: 85636
2009-10-30 23:16:10 +00:00
Chris Lattner
dd5d035302
if basic blocks are destroyed while there are *just* BlockAddress' hanging
...
around, then zap them. This is analogous to dangling constantexprs hanging
off functions.
llvm-svn: 85627
2009-10-30 22:39:36 +00:00
Chris Lattner
19788ca686
change simplifycfg to not duplicate 'unwind' instructions. Hopefully
...
this will increase the likelihood of common code getting sunk towards
the unwind.
llvm-svn: 83996
2009-10-13 18:13:05 +00:00
Chris Lattner
8d6d09379d
convert to filecheck
...
llvm-svn: 83995
2009-10-13 18:10:05 +00:00
Chris Lattner
6f55a81bb9
rename test
...
llvm-svn: 83994
2009-10-13 18:08:21 +00:00
Dan Gohman
1880092722
Change tests from "opt %s" to "opt < %s" so that opt doesn't see the
...
input filename so that opt doesn't print the input filename in the
output so that grep lines in the tests don't unintentionally match
strings in the input filename.
llvm-svn: 81537
2009-09-11 18:01:28 +00:00
Chris Lattner
e54242dc02
fix a bunch of spurious failures for people whose home directory
...
is sabre.
llvm-svn: 81528
2009-09-11 17:02:12 +00:00
Dan Gohman
4f2527cd6d
Convert a few more opt | llvm-dis to opt -S.
...
llvm-svn: 81261
2009-09-08 22:41:33 +00:00
Dan Gohman
72a13d2476
Use opt -S instead of piping bitcode output through llvm-dis.
...
llvm-svn: 81257
2009-09-08 22:34:10 +00:00
Dan Gohman
9737a63ed8
Change these tests to feed the assembly files to opt directly, instead
...
of using llvm-as, now that opt supports this.
llvm-svn: 81226
2009-09-08 16:50:01 +00:00
Devang Patel
80ae34974b
Reapply 79977.
...
Use MDNodes to encode debug info in llvm IR.
llvm-svn: 80406
2009-08-28 23:24:31 +00:00
Devang Patel
f08e35d9dc
Revert 79977. It causes llvm-gcc bootstrap failures on some platforms.
...
llvm-svn: 80073
2009-08-26 05:01:18 +00:00
Devang Patel
02aac922b4
Update DebugInfo interface to use metadata, instead of special named llvm.dbg.... global variables, to encode debugging information in llvm IR. This is mostly a mechanical change that tests metadata support very well.
...
This change speeds up llvm-gcc by more then 6% at "-O0 -g" (measured by compiling InstructionCombining.cpp!)
llvm-svn: 79977
2009-08-25 05:24:07 +00:00