Index: lib/CodeGen/BlockGenerators.cpp =================================================================== --- lib/CodeGen/BlockGenerators.cpp +++ lib/CodeGen/BlockGenerators.cpp @@ -235,6 +235,16 @@ if (Value *PreloadLoad = GlobalMap.lookup(Load)) return PreloadLoad; + // Optimization passes (Invariant Load Hoisting, DeLICM) can remove loads when + // replaced by a load at another location. The invariant load case is caught + // by the lookup in GlobalMap which contains the value. In other cases the + // optimization pass is responsible to ensure that the load's value is not + // used, either by replacing all uses or it wasn't used in the first place. We + // need to return some value because VectorBlockGenerator might multiplex it + // into a vector register, even though the vector component is not used. + if (!Stmt.getArrayAccessOrNULLFor(Load)) + return UndefValue::get(Load->getType()); + Value *NewPointer = generateLocationAccessed(Stmt, Load, BBMap, LTS, NewAccesses); Value *ScalarLoad = Builder.CreateAlignedLoad( @@ -250,6 +260,12 @@ void BlockGenerator::generateArrayStore(ScopStmt &Stmt, StoreInst *Store, ValueMapT &BBMap, LoopToScevMapT <S, isl_id_to_ast_expr *NewAccesses) { + // Optimization passes (DeLICM) can remove stores when deemed unnecessary or + // replaced by a store at another location. In this case do not generate a + // StoreInst. + if (!Stmt.getArrayAccessOrNULLFor(Store)) + return; + Value *NewPointer = generateLocationAccessed(Stmt, Store, BBMap, LTS, NewAccesses); Value *ValueOperand = getNewValue(Stmt, Store->getValueOperand(), BBMap, LTS,