Index: llvm/include/llvm/Transforms/Scalar.h =================================================================== --- llvm/include/llvm/Transforms/Scalar.h +++ llvm/include/llvm/Transforms/Scalar.h @@ -131,7 +131,7 @@ // // LICM - This pass is a loop invariant code motion and memory promotion pass. // -Pass *createLICMPass(); +Pass *createLICMPass(bool TryHoistingLoadOnly = false); Pass *createLICMPass(unsigned LicmMssaOptCap, unsigned LicmMssaNoAccForPromotionCap); Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp +++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp @@ -562,7 +562,7 @@ addPass(createEarlyCSEPass()); // Do loop invariant code motion in case part of the lowered result is // invariant. - addPass(createLICMPass()); + addPass(createLICMPass(/*TryHoistingLoadOnly*/ true)); } // Add Control Flow Guard checks. Index: llvm/lib/Transforms/Scalar/LICM.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LICM.cpp +++ llvm/lib/Transforms/Scalar/LICM.cpp @@ -332,7 +332,10 @@ INITIALIZE_PASS_END(LegacyLICMPass, "licm", "Loop Invariant Code Motion", false, false) -Pass *llvm::createLICMPass() { return new LegacyLICMPass(); } +Pass *llvm::createLICMPass(bool TryHoistingLoadOnly) { + EnableLoadHoistOnly = TryHoistingLoadOnly; + return new LegacyLICMPass(); +} Pass *llvm::createLICMPass(unsigned LicmMssaOptCap, unsigned LicmMssaNoAccForPromotionCap) { return new LegacyLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap); Index: llvm/test/Transforms/LICM/AArch64/hoist-load-without-store.ll =================================================================== --- llvm/test/Transforms/LICM/AArch64/hoist-load-without-store.ll +++ llvm/test/Transforms/LICM/AArch64/hoist-load-without-store.ll @@ -14,10 +14,12 @@ ;; } ; RUN: opt -licm -licm-load-hoisting-only -mtriple aarch64-linux-gnu -S < %s | FileCheck %s +; RUN: llc -O3 -print-after=codegenprepare < %s 2>&1 | FileCheck %s ; CHECK-LABEL: for.body.preheader: -; CHECK: %u.promoted = load i32, i32* @u -; CHECK: %v.promoted = load i32, i32* @v +; CHECK: load i32, i32* @u +; CHECK-NEXT: load i32, i32* @v +; CHECK-NEXT: br label %for.body ; ModuleID = './test.ll' source_filename = "test.c"