minor cleanup to SROA: when lowering type unsafe accesses to
[oota-llvm.git] / lib / Transforms / Scalar / ScalarReplAggregates.cpp
index eefcbb44dbc3c118c7e11c1650e93d9791c30fb1..cae21e95fd5a3653342654c2ca0a4ea08474b429 100644 (file)
@@ -1655,7 +1655,12 @@ void SROA::RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocaInst *AI,
       SrcField = BinaryOperator::CreateShl(SrcField, ShiftVal, "", LI);
     }
 
-    ResultVal = BinaryOperator::CreateOr(SrcField, ResultVal, "", LI);
+    // Don't create an 'or x, 0' on the first iteration.
+    if (!isa<Constant>(ResultVal) ||
+        !cast<Constant>(ResultVal)->isNullValue())
+      ResultVal = BinaryOperator::CreateOr(SrcField, ResultVal, "", LI);
+    else
+      ResultVal = SrcField;
   }
 
   // Handle tail padding by truncating the result