[PATCH] D22122: [SCCP] Teach the pass about bitcasts

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 12:21:04 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL274905: [SCCP] Fold constants as we build them whne visiting cast instructions. (authored by davide).

Changed prior to commit:
  http://reviews.llvm.org/D22122?vs=63164&id=63288#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D22122

Files:
  llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
  llvm/trunk/test/Transforms/SCCP/bitcast.ll

Index: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
+++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
@@ -760,8 +760,10 @@
   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
Index: llvm/trunk/test/Transforms/SCCP/bitcast.ll
===================================================================
--- llvm/trunk/test/Transforms/SCCP/bitcast.ll
+++ llvm/trunk/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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22122.63288.patch
Type: text/x-patch
Size: 1257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160708/cdce70ec/attachment.bin>


More information about the llvm-commits mailing list