[llvm] r356218 - [CGP] add another bailout for degenerate code (PR41064)

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 14 16:14:31 PDT 2019


Author: spatel
Date: Thu Mar 14 16:14:31 2019
New Revision: 356218

URL: http://llvm.org/viewvc/llvm-project?rev=356218&view=rev
Log:
[CGP] add another bailout for degenerate code (PR41064)

This is almost the same as:
rL355345
...and should prevent any potential crashing from examples like:
https://bugs.llvm.org/show_bug.cgi?id=41064
...although the bug was masked by:
rL355823
...and I'm not sure how to repro the problem after that change.

Modified:
    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
    llvm/trunk/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll

Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=356218&r1=356217&r2=356218&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Thu Mar 14 16:14:31 2019
@@ -1267,8 +1267,12 @@ static bool combineToUAddWithOverflow(Cm
 static bool combineToUSubWithOverflow(CmpInst *Cmp, const TargetLowering &TLI,
                                       const DataLayout &DL, DominatorTree &DT,
                                       bool &ModifiedDT) {
-  // Convert (A u> B) to (A u< B) to simplify pattern matching.
+  // We are not expecting non-canonical/degenerate code. Just bail out.
   Value *A = Cmp->getOperand(0), *B = Cmp->getOperand(1);
+  if (isa<Constant>(A) && isa<Constant>(B))
+    return false;
+
+  // Convert (A u> B) to (A u< B) to simplify pattern matching.
   ICmpInst::Predicate Pred = Cmp->getPredicate();
   if (Pred == ICmpInst::ICMP_UGT) {
     std::swap(A, B);

Modified: llvm/trunk/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll?rev=356218&r1=356217&r2=356218&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll (original)
+++ llvm/trunk/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll Thu Mar 14 16:14:31 2019
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -codegenprepare -S < %s | FileCheck %s
 ; RUN: opt -enable-debugify -codegenprepare -S < %s 2>&1 | FileCheck %s -check-prefix=DEBUG
 
@@ -454,6 +455,26 @@ define void @foo() {
   unreachable
 }
 
+; Similarly for usubo.
+
+define i1 @bar2() {
+; CHECK-LABEL: @bar2(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i64 1, 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %cmp = icmp eq i64 1, 0
+  ret i1 %cmp
+}
+
+define i64 @foo2(i8 *%p) {
+; CHECK-LABEL: @foo2(
+; CHECK-NEXT:    [[SUB:%.*]] = add nsw i64 1, -1
+; CHECK-NEXT:    ret i64 [[SUB]]
+;
+  %sub = add nsw i64 1, -1
+  ret i64 %sub
+}
+
 
 ; Check that every instruction inserted by -codegenprepare has a debug location.
 ; DEBUG: CheckModuleDebugify: PASS




More information about the llvm-commits mailing list