LSR cleanup: potential bug caught by PVS-Studio.
authorAndrew Trick <atrick@apple.com>
Mon, 26 Mar 2012 18:03:16 +0000 (18:03 +0000)
committerAndrew Trick <atrick@apple.com>
Mon, 26 Mar 2012 18:03:16 +0000 (18:03 +0000)
Thanks Andrey.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153451 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopStrengthReduce.cpp

index c5996039a043d03544d665cdf28e95df0e9ad2a3..60b7e62729aadfeecbc0e24f49f14a43ba106575 100644 (file)
@@ -2497,13 +2497,14 @@ void LSRInstance::ChainInstruction(Instruction *UserInst, Instruction *IVOper,
   for (Value::use_iterator UseIter = IVOper->use_begin(),
          UseEnd = IVOper->use_end(); UseIter != UseEnd; ++UseIter) {
     Instruction *OtherUse = dyn_cast<Instruction>(*UseIter);
+    if (!OtherUse || OtherUse == UserInst)
+      continue;
     if (SE.isSCEVable(OtherUse->getType())
         && !isa<SCEVUnknown>(SE.getSCEV(OtherUse))
         && IU.isIVUserOrOperand(OtherUse)) {
       continue;
     }
-    if (OtherUse && OtherUse != UserInst)
-      NearUsers.insert(OtherUse);
+    NearUsers.insert(OtherUse);
   }
 
   // Since this user is part of the chain, it's no longer considered a use