OSDN Git Service

[ConstantFolding] Use ConstantExpr::getWithOperands
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 29 Jul 2016 03:27:31 +0000 (03:27 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 29 Jul 2016 03:27:31 +0000 (03:27 +0000)
ConstantExpr::getWithOperands does much of the hard work that
ConstantFoldInstOperandsImpl tries to do but more completely.

This lets us fold ExtractValue/InsertValue expressions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277100 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ConstantFolding.cpp
test/Transforms/InstCombine/cast.ll
test/Transforms/InstSimplify/pr28725.ll

index 7ee3e8c..c7f656a 100644 (file)
@@ -938,6 +938,9 @@ Constant *ConstantFoldInstOperandsImpl(const Value *InstOrCE, Type *DestTy,
                                           Ops[0], Ops.slice(1));
   }
 
+  if (auto *CE = dyn_cast<ConstantExpr>(InstOrCE))
+    return CE->getWithOperands(Ops);
+
   switch (Opcode) {
   default: return nullptr;
   case Instruction::ICmp:
index e450911..2acb687 100644 (file)
@@ -1375,7 +1375,7 @@ define i16 @PR24763(i8 %V) {
 
 define i64 @PR28745() {
 ; CHECK-LABEL: @PR28745(
-; CHECK-NEXT:    ret i64 zext (i32 extractvalue ({ i32 } select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> <i32 1> to <2 x i16>), i32 0), i16 0), { i32 } { i32 1 }, { i32 } zeroinitializer), 0) to i64)
+; CHECK-NEXT:    ret i64 1
 
   %b = zext i32 extractvalue ({ i32 } select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> <i32 1> to <2 x i16>), i32 0), i16 0), { i32 } { i32 1 }, { i32 } zeroinitializer), 0) to i64
   ret i64 %b
index 420bf4d..b85fc10 100644 (file)
@@ -10,4 +10,4 @@ entry:
 }
 
 ; CHECK-LABEL: @test1(
-; CHECK: ret <2 x i16> <i16 extractvalue (%S select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> <i32 1> to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0), i16 0>
+; CHECK: ret <2 x i16> zeroinitializer