[PATCH] D149134: [LICM] Don't try to constant fold instructions
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 00:27:06 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG43436993f48b: [LICM] Don't try to constant fold instructions (authored by nikic).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149134/new/
https://reviews.llvm.org/D149134
Files:
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/test/Transforms/LICM/hoisting.ll
llvm/test/Transforms/LICM/pr32129.ll
llvm/test/Transforms/LICM/scalar-promote.ll
Index: llvm/test/Transforms/LICM/scalar-promote.ll
===================================================================
--- llvm/test/Transforms/LICM/scalar-promote.ll
+++ llvm/test/Transforms/LICM/scalar-promote.ll
@@ -41,15 +41,17 @@
define void @test2(i32 %i) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: Entry:
-; CHECK-NEXT: [[DOTPROMOTED:%.*]] = load i32, ptr getelementptr inbounds (i32, ptr @X, i64 1), align 4
+; CHECK-NEXT: [[X1:%.*]] = getelementptr i32, ptr @X, i64 1
+; CHECK-NEXT: [[X2:%.*]] = getelementptr i32, ptr @X, i64 1
+; CHECK-NEXT: [[X1_PROMOTED:%.*]] = load i32, ptr [[X1]], align 4
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: Loop:
-; CHECK-NEXT: [[V1:%.*]] = phi i32 [ [[V:%.*]], [[LOOP]] ], [ [[DOTPROMOTED]], [[ENTRY:%.*]] ]
-; CHECK-NEXT: [[V]] = add i32 [[V1]], 1
+; CHECK-NEXT: [[A1:%.*]] = phi i32 [ [[V:%.*]], [[LOOP]] ], [ [[X1_PROMOTED]], [[ENTRY:%.*]] ]
+; CHECK-NEXT: [[V]] = add i32 [[A1]], 1
; CHECK-NEXT: br i1 false, label [[LOOP]], label [[EXIT:%.*]]
; CHECK: Exit:
; CHECK-NEXT: [[V_LCSSA:%.*]] = phi i32 [ [[V]], [[LOOP]] ]
-; CHECK-NEXT: store i32 [[V_LCSSA]], ptr getelementptr inbounds (i32, ptr @X, i64 1), align 4
+; CHECK-NEXT: store i32 [[V_LCSSA]], ptr [[X1]], align 4
; CHECK-NEXT: ret void
;
Entry:
Index: llvm/test/Transforms/LICM/pr32129.ll
===================================================================
--- llvm/test/Transforms/LICM/pr32129.ll
+++ llvm/test/Transforms/LICM/pr32129.ll
@@ -6,6 +6,8 @@
define void @test() {
; CHECK-LABEL: define void @test() {
; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 0, 400
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[TMP0]], i32 9) [ "deopt"() ]
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header.loopexit:
; CHECK-NEXT: br label [[HEADER]]
Index: llvm/test/Transforms/LICM/hoisting.ll
===================================================================
--- llvm/test/Transforms/LICM/hoisting.ll
+++ llvm/test/Transforms/LICM/hoisting.ll
@@ -83,16 +83,17 @@
}
-; This loop invariant instruction should be constant folded, not hoisted.
+; Don't bother constant folding the add, just hoist it.
define i32 @test3(i1 %c) {
; CHECK-LABEL: @test3(
; CHECK-NEXT: [[A:%.*]] = load i32, ptr @X, align 4
+; CHECK-NEXT: [[B:%.*]] = add i32 4, 2
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: Loop:
-; CHECK-NEXT: call void @foo2(i32 6)
+; CHECK-NEXT: call void @foo2(i32 [[B]])
; CHECK-NEXT: br i1 [[C:%.*]], label [[LOOP]], label [[OUT:%.*]]
; CHECK: Out:
-; CHECK-NEXT: [[B_LCSSA:%.*]] = phi i32 [ 6, [[LOOP]] ]
+; CHECK-NEXT: [[B_LCSSA:%.*]] = phi i32 [ [[B]], [[LOOP]] ]
; CHECK-NEXT: [[C:%.*]] = sub i32 [[A]], [[B_LCSSA]]
; CHECK-NEXT: ret i32 [[C]]
;
Index: llvm/lib/Transforms/Scalar/LICM.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LICM.cpp
+++ llvm/lib/Transforms/Scalar/LICM.cpp
@@ -44,7 +44,6 @@
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/CaptureTracking.h"
-#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/GuardUtils.h"
#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
#include "llvm/Analysis/Loads.h"
@@ -891,21 +890,6 @@
continue;
for (Instruction &I : llvm::make_early_inc_range(*BB)) {
- // Try constant folding this instruction. If all the operands are
- // constants, it is technically hoistable, but it would be better to
- // just fold it.
- if (Constant *C = ConstantFoldInstruction(
- &I, I.getModule()->getDataLayout(), TLI)) {
- LLVM_DEBUG(dbgs() << "LICM folding inst: " << I << " --> " << *C
- << '\n');
- // FIXME MSSA: Such replacements may make accesses unoptimized (D51960).
- I.replaceAllUsesWith(C);
- if (isInstructionTriviallyDead(&I, TLI))
- eraseInstruction(I, *SafetyInfo, MSSAU);
- Changed = true;
- continue;
- }
-
// Try hoisting the instruction out to the preheader. We can only do
// this if all of the operands of the instruction are loop invariant and
// if it is safe to hoist the instruction. We also check block frequency
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149134.517075.patch
Type: text/x-patch
Size: 4348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230426/8f57eba7/attachment.bin>
More information about the llvm-commits
mailing list