[llvm-commits] [llvm] r172145 - in /llvm/trunk: lib/Transforms/Scalar/LoopIdiomRecognize.cpp test/Transforms/LoopIdiom/X86/popcnt.ll

Shuxin Yang shuxin.llvm at gmail.com
Thu Jan 10 15:32:01 PST 2013


Author: shuxin_yang
Date: Thu Jan 10 17:32:01 2013
New Revision: 172145

URL: http://llvm.org/viewvc/llvm-project?rev=172145&view=rev
Log:
PR14904: Segmentation fault running pass 'Recognize loop idioms'

The root cause is mistakenly taking for granted that 
    "dyn_cast<Instruction>(a-Value)"
return a non-NULL instruction.

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
    llvm/trunk/test/Transforms/LoopIdiom/X86/popcnt.ll

Modified: llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp?rev=172145&r1=172144&r2=172145&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp Thu Jan 10 17:32:01 2013
@@ -407,7 +407,7 @@
 
   // step 2: detect instructions corresponding to "x2 = x1 & (x1 - 1)"
   {
-    if (DefX2->getOpcode() != Instruction::And)
+    if (!DefX2 || DefX2->getOpcode() != Instruction::And)
       return false;
 
     BinaryOperator *SubOneOp;

Modified: llvm/trunk/test/Transforms/LoopIdiom/X86/popcnt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopIdiom/X86/popcnt.ll?rev=172145&r1=172144&r2=172145&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopIdiom/X86/popcnt.ll (original)
+++ llvm/trunk/test/Transforms/LoopIdiom/X86/popcnt.ll Thu Jan 10 17:32:01 2013
@@ -118,3 +118,23 @@
   %c.0.lcssa = phi i32 [ 0, %entry ], [ %inc, %while.body ]
   ret i32 %c.0.lcssa
 }
+
+define i32 @PopCntCrash3(i64 %a, i32 %x) {
+entry:
+  %tobool3 = icmp eq i64 %a, 0
+  %cmp = icmp eq i32 %x, 0
+  br i1 %tobool3, label %while.end, label %while.body
+
+while.body:                                       ; preds = %entry, %while.body
+  %c.05 = phi i32 [ %inc, %while.body ], [ 0, %entry ]
+  %a.addr.04 = phi i64 [ %and, %while.body ], [ %a, %entry ]
+  %inc = add nsw i32 %c.05, 1
+  %sub = add i64 %a.addr.04, -1
+  %and = and i64 %sub, %a.addr.04
+  %tobool = icmp eq i64 %and, 0
+  br i1 %cmp, label %while.end, label %while.body
+
+while.end:                                        ; preds = %while.body, %entry
+  %c.0.lcssa = phi i32 [ 0, %entry ], [ %inc, %while.body ]
+  ret i32 %c.0.lcssa
+}





More information about the llvm-commits mailing list