Use ConstantExpr::getExtractElement when constant-folding vectors
authorDan Gohman <gohman@apple.com>
Fri, 27 Apr 2012 00:54:36 +0000 (00:54 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 27 Apr 2012 00:54:36 +0000 (00:54 +0000)
commit97b44f9b8026fce47c1c882347f88af91c6e74c1
tree3b832826f8ead1579261dc3762d99ddefa4c82cf
parentf9f1c7aa89c87a9c8d6b8b317957b24e44f66570
Use ConstantExpr::getExtractElement when constant-folding vectors
instead of getAggregateElement. This has the advantage of being
more consistent and allowing higher-level constant folding to
procede even if an inner extract element cannot be folded.

Make ConstantFoldInstruction call ConstantFoldConstantExpression
on the instruction's operands, making it more consistent with
ConstantFoldConstantExpression itself. This makes sure that
ConstantExprs get TargetData-aware folding before being handed
off as operands for further folding.

This causes more expressions to be folded, but due to a known
shortcoming in constant folding, this currently has the side effect
of stripping a few more nuw and inbounds flags in the non-targetdata
side of constant-fold-gep.ll. This is mostly harmless.

This fixes rdar://11324230.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155682 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ConstantFolding.cpp
lib/VMCore/ConstantFold.cpp
test/Other/constant-fold-gep.ll
test/Transforms/SCCP/vector-bitcast.ll [new file with mode: 0644]