[llvm] r274905 - [SCCP] Fold constants as we build them whne visiting cast instructions.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 8 12:13:41 PDT 2016
Author: davide
Date: Fri Jul 8 14:13:40 2016
New Revision: 274905
URL: http://llvm.org/viewvc/llvm-project?rev=274905&view=rev
Log:
[SCCP] Fold constants as we build them whne visiting cast instructions.
This should be slightly more efficient and could avoid spurious overdefined
markings, as Eli pointed out.
Differential Revision: http://reviews.llvm.org/D22122
Added:
llvm/trunk/test/Transforms/SCCP/bitcast.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=274905&r1=274904&r2=274905&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Fri Jul 8 14:13:40 2016
@@ -760,8 +760,10 @@ void SCCPSolver::visitCastInst(CastInst
if (OpSt.isOverdefined()) // Inherit overdefinedness of operand
markOverdefined(&I);
else if (OpSt.isConstant()) {
- Constant *C =
- ConstantExpr::getCast(I.getOpcode(), OpSt.getConstant(), I.getType());
+ // Fold the constant as we build.
+ Constant *C = ConstantFoldCastOperand(
+ I.getOpcode(), getValueState(I.getOperand(0)).getConstant(),
+ I.getType(), DL);
if (isa<UndefValue>(C))
return;
// Propagate constant value
Added: llvm/trunk/test/Transforms/SCCP/bitcast.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SCCP/bitcast.ll?rev=274905&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SCCP/bitcast.ll (added)
+++ llvm/trunk/test/Transforms/SCCP/bitcast.ll Fri Jul 8 14:13:40 2016
@@ -0,0 +1,9 @@
+; RUN: opt < %s -ipsccp -S | FileCheck %s
+
+define i128 @vector_to_int_cast() {
+ %A = bitcast <4 x i32> <i32 1073741824, i32 1073741824, i32 1073741824, i32 1073741824> to i128
+ ret i128 %A
+}
+
+; CHECK: define i128 @vector_to_int_cast(
+; CHECK-NEXT: ret i128 85070591750041656499021422275829170176
More information about the llvm-commits
mailing list