[PATCH] D54359: [InstCombine] Remove a couple of asserts based on incorrect assumptions

Mandeep Singh Grang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 9 15:03:05 PST 2018


mgrang created this revision.
mgrang added reviewers: craig.topper, spatel, dmgreen.

These asserts are based on the assumption that the order of true/false operands in a select and those in the compare would always be the same.


Repository:
  rL LLVM

https://reviews.llvm.org/D54359

Files:
  lib/Transforms/InstCombine/InstCombineSelect.cpp
  test/Transforms/InstCombine/select-pr39595.ll


Index: test/Transforms/InstCombine/select-pr39595.ll
===================================================================
--- /dev/null
+++ test/Transforms/InstCombine/select-pr39595.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+%0 = type { %1 }
+%1 = type { %2* }
+%2 = type { i32, i32* }
+
+$foo = comdat any
+
+; Function Attrs: inlinehint norecurse
+define linkonce_odr dso_local i32 @foo(%0* dereferenceable(4)) local_unnamed_addr comdat !prof !1 {
+; CHECK-LABEL: foo
+; CHECK:      [[TMP1:%.*]] = load i32*, i32** inttoptr (i64 8 to i32**), align 8
+; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[TMP1]], align 4
+; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* inttoptr (i64 4 to i32*), align 4
+; CHECK-NEXT: [[TMP4:%.*]] = icmp ugt i32 [[TMP2]], [[TMP3]]
+; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP4]], i32 [[TMP2]], i32 [[TMP3]], !prof ![[$MD1:[0-9]+]]
+; CHECK-DAG: ![[$MD1]] = !{!"branch_weights", i32 1, i32 6}
+
+  %2 = getelementptr inbounds %2, %2* null, i32 0, i32 1
+  %3 = load i32*, i32** %2, align 4
+  %4 = load i32, i32* %3, align 4
+  %5 = xor i32 %4, -1
+  %6 = getelementptr inbounds i32, i32* null, i32 1
+  %7 = load i32, i32* %6, align 4
+  %8 = xor i32 %7, -1
+  %9 = icmp ugt i32 %5, %8
+  %10 = select i1 %9, i32 %8, i32 %5, !prof !2
+  ret i32 %10
+}
+
+!1 = !{!"function_entry_count", i64 1}
+!2 = !{!"branch_weights", i32 1, i32 6}
Index: lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1820,14 +1820,8 @@
           if (MDNode *MD = SI.getMetadata(LLVMContext::MD_prof)) {
             cast<SelectInst>(NewMinMax)->setMetadata(LLVMContext::MD_prof, MD);
             // Swap the metadata if the operands are swapped.
-            if (Swapped) {
-              assert(X == SI.getFalseValue() && Y == SI.getTrueValue() &&
-                     "Unexpected operands.");
+            if (Swapped)
               cast<SelectInst>(NewMinMax)->swapProfMetadata();
-            } else {
-              assert(X == SI.getTrueValue() && Y == SI.getFalseValue() &&
-                     "Unexpected operands.");
-            }
           }
 
           return BinaryOperator::CreateNot(NewMinMax);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54359.173452.patch
Type: text/x-patch
Size: 2324 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181109/10c4f758/attachment.bin>


More information about the llvm-commits mailing list