Chris Lattner
0dc48180de
fix PR5978 by peeling the loop so that we avoid shifting the
...
result int by 8 for the first byte. While normally harmless,
if the result is smaller than a byte, this shift is invalid.
llvm-svn: 93018
2010-01-08 19:02:23 +00:00
Chris Lattner
8a0648118b
constant fold nasty constant expressions formed by llvm-gcc,
...
wrapping up PR3351.
llvm-svn: 92410
2010-01-02 01:22:23 +00:00
Chris Lattner
107fc93d48
Fix PR5551 by not ignoring the top level constantexpr when
...
folding a load from constant.
llvm-svn: 90545
2009-12-04 06:29:29 +00:00
Chris Lattner
851aea6ce2
fix PR5673 by being more careful about pointers to functions.
...
llvm-svn: 90369
2009-12-03 01:05:45 +00:00
Nick Lewycky
116b145b02
Teach ConstantFolding to do a better job when folding gep(bitcast).
...
This permits the devirtualization of llvm.org/PR3100#c9 when compiled by clang.
llvm-svn: 90099
2009-11-29 21:40:55 +00:00
Dan Gohman
58bb87921b
Make ConstantFoldConstantExpression recursively visit the entire
...
ConstantExpr, not just the top-level operator. This allows it to
fold many more constants.
Also, make GlobalOpt call ConstantFoldConstantExpression on
GlobalVariable initializers.
llvm-svn: 89659
2009-11-23 16:22:21 +00:00
Chris Lattner
131172dc76
fix ConstantFoldCompareInstOperands to take the LHS/RHS as
...
individual operands instead of taking a temporary array
llvm-svn: 86619
2009-11-09 23:06:58 +00:00
Chris Lattner
903ae55e1c
remove a bunch of extraneous LLVMContext arguments
...
from various APIs, addressing PR5325.
llvm-svn: 86231
2009-11-06 04:27:31 +00:00
Chris Lattner
d8db8b6952
Teach FoldBitCast to be able to handle bitcasts from (e.g.) i128 -> <4 x float>.
...
This allows us to simplify this:
union vec2d {
double e[2];
double v __attribute__((vector_size(16)));
};
typedef union vec2d vec2d;
static vec2d a={{1,2}}, b={{3,4}};
vec2d foo () {
return (vec2d){ .v = a.v + b.v * (vec2d){{5,5}}.v };
}
down to:
define %0 @foo() nounwind ssp {
entry:
%mrv5 = insertvalue %0 undef, double 1.600000e+01, 0 ; <%0> [#uses=1]
%mrv6 = insertvalue %0 %mrv5, double 2.200000e+01, 1 ; <%0> [#uses=1]
ret %0 %mrv6
}
instead of:
define %0 @foo() nounwind ssp {
entry:
%mrv5 = insertvalue %0 undef, double extractelement (<2 x double> fadd (<2 x double> fmul (<2 x double> bitcast (<1 x i128> <i128 85174437667405312423031577302488055808> to <2 x double>), <2 x double> <double 3.000000e+00, double 4.000000e+00>), <2 x double> <double 1.000000e+00, double 2.000000e+00>), i32 0), 0 ; <%0> [#uses=1]
%mrv6 = insertvalue %0 %mrv5, double extractelement (<2 x double> fadd (<2 x double> fmul (<2 x double> bitcast (<1 x i128> <i128 85174437667405312423031577302488055808> to <2 x double>), <2 x double> <double 3.000000e+00, double 4.000000e+00>), <2 x double> <double 1.000000e+00, double 2.000000e+00>), i32 1), 1 ; <%0> [#uses=1]
ret %0 %mrv6
}
llvm-svn: 85040
2009-10-25 06:15:37 +00:00
Chris Lattner
d80c1f61d2
move FoldBitCast earlier in the file, and use it instead of
...
ConstantExpr::getBitCast in various places.
llvm-svn: 85039
2009-10-25 06:08:26 +00:00
Chris Lattner
f6cb8d6b90
refactor FoldBitCast to reduce nesting and to always return a constantexpr
...
instead of returning null on failure. No functionality change.
llvm-svn: 85038
2009-10-25 06:02:57 +00:00
Chris Lattner
5f456758c6
various cleanups suggested by Duncan
...
llvm-svn: 84993
2009-10-24 05:27:19 +00:00
Chris Lattner
9a1f5c9f90
fix PR5287, a serious regression from my previous patches. Thanks to
...
Duncan for the nice tiny testcase.
llvm-svn: 84992
2009-10-24 05:22:15 +00:00
Chris Lattner
4874f5bce5
teach libanalysis to simplify vector loads with bitcast sources. This
...
implements something out of Target/README.txt producing:
_foo: ## @foo
movl 4(%esp), %eax
movapd LCPI1_0, %xmm0
movapd %xmm0, (%eax)
ret $4
instead of:
_foo: ## @foo
movl 4(%esp), %eax
movapd _b, %xmm0
mulpd LCPI1_0, %xmm0
addpd _a, %xmm0
movapd %xmm0, (%eax)
ret $4
llvm-svn: 84942
2009-10-23 06:57:37 +00:00
Chris Lattner
2ee1f0f0b5
enhance FoldReinterpretLoadFromConstPtr to handle loads of up to 32
...
bytes (i256).
llvm-svn: 84941
2009-10-23 06:50:36 +00:00
Chris Lattner
b1d2706a4c
teach libanalysis to fold int and fp loads from almost arbitrary
...
non-type-safe constant initializers. This sort of thing happens
quite a bit for 4-byte loads out of string constants, unions,
bitfields, and an interesting endianness check from sqlite, which
is something like this:
const int sqlite3one = 1;
# define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
# define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
# define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
all of these macros now constant fold away.
This implements PR3152 and is based on a patch started by Eli, but heavily
modified and extended.
llvm-svn: 84936
2009-10-23 06:23:49 +00:00
Chris Lattner
cd80b1711b
move another load optimization from instcombine -> libanalysis.
...
llvm-svn: 84841
2009-10-22 06:44:07 +00:00
Chris Lattner
3fb4c19b7d
move 'loading i32 from string' optimization from instcombine
...
to libanalysis. Instcombine shrinking... does this even
make sense???
llvm-svn: 84840
2009-10-22 06:38:35 +00:00
Chris Lattner
2c8c8533b1
Move some constant folding logic for loads out of instcombine into
...
Analysis/ConstantFolding.cpp. This doesn't change the behavior of
instcombine but makes other clients of ConstantFoldInstruction
able to handle loads. This was partially extracted from Eli's patch
in PR3152.
llvm-svn: 84836
2009-10-22 06:25:11 +00:00
Evan Phoenix
1b803795c7
Extend ConstantFolding to understand signed overflow variants
...
llvm-svn: 83338
2009-10-05 22:53:52 +00:00
Dan Gohman
176e47a413
Remove an unnnecessary LLVMContext argument in
...
ConstantFoldLoadThroughGEPConstantExpr.
llvm-svn: 83311
2009-10-05 16:36:26 +00:00
Chris Lattner
7d19c8841c
teach the optimizer how to constant fold uadd/usub intrinsics.
...
llvm-svn: 83295
2009-10-05 05:26:04 +00:00
Chris Lattner
8b72a24a35
simplify this code a bunch.
...
llvm-svn: 83294
2009-10-05 05:06:24 +00:00
Chris Lattner
24a77e2ade
code simplifications.
...
llvm-svn: 83292
2009-10-05 05:00:35 +00:00
Chris Lattner
6302039748
simplify some code
...
llvm-svn: 81961
2009-09-16 00:08:07 +00:00
Dan Gohman
aa66e3d968
Teach lib/VMCore/ConstantFold.cpp how to set the inbounds keyword and
...
how to fold notionally-out-of-bounds array getelementptr indices instead
of just doing these in lib/Analysis/ConstantFolding.cpp, because it can
be done in a fairly general way without TargetData, and because not all
constants are visited by lib/Analysis/ConstantFolding.cpp. This enables
more constant folding.
Also, set the "inbounds" flag when the getelementptr indices are
one-past-the-end.
llvm-svn: 81483
2009-09-11 00:04:14 +00:00
Dan Gohman
97819c7fe8
Give these files top-level comments that describe the current code.
...
llvm-svn: 81473
2009-09-10 23:07:18 +00:00
Dan Gohman
b9b2864a49
Revert 80959. It isn't sufficient to solve the full problem. And it
...
introduced regressions in the Ocaml bindings tests.
llvm-svn: 80969
2009-09-03 23:34:49 +00:00
Dan Gohman
e5ec3c1a26
Remove the API for creating ConstantExprs with the nsw, nuw, inbounds,
...
and exact flags. Because ConstantExprs are uniqued, creating an
expression with this flag causes all expressions with the same operands
to have the same flag, which may not be safe. Add, sub, mul, and sdiv
ConstantExprs are usually folded anyway, so the main interesting flag
here is inbounds, and the constant folder already knows how to set the
inbounds flag automatically in most cases, so there isn't an urgent need
for the API support.
This can be reconsidered in the future, but for now just removing these
API bits eliminates a source of potential trouble with little downside.
llvm-svn: 80959
2009-09-03 22:17:40 +00:00
Chris Lattner
1f08c79edc
fix PR4848 an infinite loop when indexing down through a recursive gep
...
and we get the original pointer type. This doesn't mean that we're
at the first pointer being indexed. Correct the predicate.
llvm-svn: 80762
2009-09-02 05:35:45 +00:00
Dan Gohman
aac0378610
Don't assume that the operand of an inttoptr is an pointer-sized integer.
...
llvm-svn: 79651
2009-08-21 18:27:26 +00:00
Dan Gohman
d240c19451
Change getelementptr folding to use APInt instead of uint64_t for
...
offset computations. This fixes a truncation bug on targets that
don't have 64-bit pointers.
llvm-svn: 79639
2009-08-21 16:52:54 +00:00
Dan Gohman
d9766dcb85
Various comment and whitespace cleanups.
...
llvm-svn: 79533
2009-08-20 16:42:55 +00:00
Dan Gohman
cc511acf87
Fix a bug in the over-index constant folding. When over-indexing an
...
array member of a struct, it's possible to land in an arbitrary position
inside that struct, such that attempting to find further getelementptr
indices will fail. In such cases, folding cannot be done.
llvm-svn: 79485
2009-08-19 22:46:59 +00:00
Dan Gohman
bc59c24278
Canonicalize indices in a constantexpr GEP. If Indices exceed the
...
static extents of the static array type, it causes GlobalOpt and
other passes to be more conservative. This canonicalization also
allows the constant folder to add "inbounds" to GEPs.
llvm-svn: 79440
2009-08-19 18:18:36 +00:00
Owen Anderson
9df206d02d
Push LLVMContexts through the IntegerType APIs.
...
llvm-svn: 78948
2009-08-13 21:58:54 +00:00
Owen Anderson
1dc40e205b
Move a few more APIs back to 2.5 forms. The only remaining ones left to change back are
...
metadata related, which I'm waiting on to avoid conflicting with Devang.
llvm-svn: 77721
2009-07-31 20:28:14 +00:00
Owen Anderson
93ccaf5c60
Move more code back to 2.5 APIs.
...
llvm-svn: 77635
2009-07-30 23:03:37 +00:00
Owen Anderson
881d928f9b
Move types back to the 2.5 API.
...
llvm-svn: 77516
2009-07-29 22:17:13 +00:00
Owen Anderson
0ce2151b36
Move ConstantExpr to 2.5 API.
...
llvm-svn: 77494
2009-07-29 18:55:55 +00:00
Owen Anderson
390e9778d4
Return ConstantVector to 2.5 API.
...
llvm-svn: 77366
2009-07-28 21:19:26 +00:00
Owen Anderson
256c2c250e
Move ConstantFP construction back to the 2.5-ish API.
...
llvm-svn: 77247
2009-07-27 20:59:43 +00:00
Daniel Dunbar
64abfd0337
Remove Value::getNameLen
...
llvm-svn: 77148
2009-07-26 08:34:35 +00:00
Owen Anderson
cc33e89571
Revert the ConstantInt constructors back to their 2.5 forms where possible, thanks to contexts-on-types. More to come.
...
llvm-svn: 77011
2009-07-24 23:12:02 +00:00
Owen Anderson
cc287b28c9
Get rid of the Pass+Context magic.
...
llvm-svn: 76702
2009-07-22 00:24:57 +00:00
Torok Edwin
f955a6ef49
llvm_unreachable->llvm_unreachable(0), LLVM_UNREACHABLE->llvm_unreachable.
...
This adds location info for all llvm_unreachable calls (which is a macro now) in
!NDEBUG builds.
In NDEBUG builds location info and the message is off (it only prints
"UREACHABLE executed").
llvm-svn: 75640
2009-07-14 16:55:14 +00:00
Torok Edwin
ae8a3ff177
assert(0) -> LLVM_UNREACHABLE.
...
Make llvm_unreachable take an optional string, thus moving the cerr<< out of
line.
LLVM_UNREACHABLE is now a simple wrapper that makes the message go away for
NDEBUG builds.
llvm-svn: 75379
2009-07-11 20:10:48 +00:00
Nick Lewycky
d46a7b2d22
Remove the vicmp and vfcmp instructions. Because we never had a release with
...
these instructions, no autoupgrade or backwards compatibility support is
provided.
llvm-svn: 74991
2009-07-08 03:04:38 +00:00
Owen Anderson
121f736d9c
"LLVMContext* " --> "LLVMContext *"
...
llvm-svn: 74878
2009-07-06 23:00:19 +00:00
Owen Anderson
ad3229d281
Thread LLVMContext through the constant folding APIs, which touches a lot of files.
...
llvm-svn: 74844
2009-07-06 18:42:36 +00:00