[PATCH] D34905: Modify constraints in `llvm::canReplaceOperandWithVariable`

Leo Li via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 5 16:49:13 PDT 2017


aoli updated this revision to Diff 105360.
aoli added a comment.

Test sink common code for insertvalue.


https://reviews.llvm.org/D34905

Files:
  lib/Transforms/Utils/Local.cpp
  test/Transforms/SimplifyCFG/sink-common-code.ll


Index: test/Transforms/SimplifyCFG/sink-common-code.ll
===================================================================
--- test/Transforms/SimplifyCFG/sink-common-code.ll
+++ test/Transforms/SimplifyCFG/sink-common-code.ll
@@ -818,6 +818,30 @@
 ; CHECK: right:
 ; CHECK-NEXT:   %val1 = call i32 @call_target() [ "deopt"(i32 20) ]
 
+%T = type {i32, i32}
+
+define i32 @test_insertvalue(i1 zeroext %flag, %T %P) {
+entry:
+  br i1 %flag, label %if.then, label %if.else
+
+if.then:
+  %t1 = insertvalue %T %P, i32 0, 0
+  br label %if.end
+
+if.else:
+  %t2 = insertvalue %T %P, i32 1, 0
+  br label %if.end
+
+if.end:
+  %t = phi %T [%t1, %if.then], [%t2, %if.else]
+  ret i32 1
+}
+
+; CHECK-LABEL: @test_insertvalue
+; CHECK: select
+; CHECK: insertvalue
+; CHECK-NOT: insertvalue
+
 ; CHECK: ![[TBAA]] = !{![[TYPE:[0-9]]], ![[TYPE]], i64 0}
 ; CHECK: ![[TYPE]] = !{!"float", ![[TEXT:[0-9]]]}
 ; CHECK: ![[TEXT]] = !{!"an example type tree"}
Index: lib/Transforms/Utils/Local.cpp
===================================================================
--- lib/Transforms/Utils/Local.cpp
+++ lib/Transforms/Utils/Local.cpp
@@ -2182,10 +2182,13 @@
   case Instruction::ShuffleVector:
     // Shufflevector masks are constant.
     return OpIdx != 2;
+  case Instruction::Switch:
   case Instruction::ExtractValue:
-  case Instruction::InsertValue:
     // All operands apart from the first are constant.
     return OpIdx == 0;
+  case Instruction::InsertValue:
+    // All operands apart from the first and the second are constant.
+    return OpIdx < 2;
   case Instruction::Alloca:
     return false;
   case Instruction::GetElementPtr:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34905.105360.patch
Type: text/x-patch
Size: 1639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170705/3c327ff9/attachment.bin>


More information about the llvm-commits mailing list