[llvm] r271931 - [LoopUnrollAnalyzer] Fix a crash in analyzeLoopUnrollCost.

Michael Zolotukhin via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 6 12:21:40 PDT 2016


Author: mzolotukhin
Date: Mon Jun  6 14:21:40 2016
New Revision: 271931

URL: http://llvm.org/viewvc/llvm-project?rev=271931&view=rev
Log:
[LoopUnrollAnalyzer] Fix a crash in analyzeLoopUnrollCost.

In some cases, when simplifying with SCEV, we might consider pointer values as
just usual integer values.  Thus, we might get a different type from what we
had originally in the map of simplified values, and hence we need to check
types before operating on the values.

This fixes PR28015.

Modified:
    llvm/trunk/lib/Analysis/LoopUnrollAnalyzer.cpp
    llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll

Modified: llvm/trunk/lib/Analysis/LoopUnrollAnalyzer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopUnrollAnalyzer.cpp?rev=271931&r1=271930&r2=271931&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopUnrollAnalyzer.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopUnrollAnalyzer.cpp Mon Jun  6 14:21:40 2016
@@ -187,9 +187,11 @@ bool UnrolledInstAnalyzer::visitCmpInst(
 
   if (Constant *CLHS = dyn_cast<Constant>(LHS)) {
     if (Constant *CRHS = dyn_cast<Constant>(RHS)) {
-      if (Constant *C = ConstantExpr::getCompare(I.getPredicate(), CLHS, CRHS)) {
-        SimplifiedValues[&I] = C;
-        return true;
+      if (CLHS->getType() == CRHS->getType()) {
+        if (Constant *C = ConstantExpr::getCompare(I.getPredicate(), CLHS, CRHS)) {
+          SimplifiedValues[&I] = C;
+          return true;
+        }
       }
     }
   }

Modified: llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll?rev=271931&r1=271930&r2=271931&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll (original)
+++ llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll Mon Jun  6 14:21:40 2016
@@ -188,3 +188,19 @@ for.inc:
 for.end:
   ret void
 }
+
+define void @cmp_type_mismatch() {
+entry:
+  br label %for.header
+
+for.header:
+  br label %for.body
+
+for.body:
+  %d = phi i32* [ null, %for.header ]
+  %cmp = icmp eq i32* %d, null
+  br i1 undef, label %for.end, label %for.header
+
+for.end:
+  ret void
+}




More information about the llvm-commits mailing list