Skip to content

Commit

Permalink
[SCCP] Fold constants as we build them whne visiting cast instructions.
Browse files Browse the repository at this point in the history
This should be slightly more efficient and could avoid spurious overdefined
markings, as Eli pointed out.

Differential Revision:  http://reviews.llvm.org/D22122

llvm-svn: 274905
  • Loading branch information
dcci committed Jul 8, 2016
1 parent dca9bff commit d555bde
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions llvm/lib/Transforms/Scalar/SCCP.cpp
Expand Up @@ -760,8 +760,10 @@ void SCCPSolver::visitCastInst(CastInst &I) {
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
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/Transforms/SCCP/bitcast.ll
@@ -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

0 comments on commit d555bde

Please sign in to comment.