[PATCH] D133426: [LICM][LSR] Address a couple of special cases involving NULL.
Stefan Pintilie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 13 11:38:43 PDT 2022
stefanp updated this revision to Diff 459824.
stefanp added a comment.
Sorry that this took a few days.
Removed the code from LICM.
Added a test for the loop strength reduction. The test shows simpler code when
the guard for the NULL is added. However, there may be other tests where the
reverse is true.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133426/new/
https://reviews.llvm.org/D133426
Files:
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/test/Transforms/LoopStrengthReduce/Power/opaque-null-ptr.ll
Index: llvm/test/Transforms/LoopStrengthReduce/Power/opaque-null-ptr.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopStrengthReduce/Power/opaque-null-ptr.ll
@@ -0,0 +1,40 @@
+; RUN: llc -O3 -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 \
+; RUN: -stop-after=loop-reduce %s -o - | FileCheck %s
+
+ %0 = type <{ float }>
+
+define void @test(ptr %arg1, ptr %arg2, float %storeval) local_unnamed_addr {
+; CHECK-LABEL: test
+; CHECK: bb175:
+; CHECK-NEXT: %lsr.iv = phi i64 [ %lsr.iv.next, %bb175 ], [ 0, %bb ]
+; CHECK-NEXT: %i176 = phi i64 [ %i237, %bb175 ], [ 1, %bb ]
+; CHECK-NEXT: %i237 = add nuw nsw i64 %i176, 2
+; CHECK-NEXT: %lsr.iv.next = add nuw nsw i64 %lsr.iv, 8
+; CHECK-NEXT: %i238 = icmp slt i64 %i237, -1
+; CHECK-NEXT: br i1 %i238, label %bb175, label %bb239
+
+bb:
+ %i21 = getelementptr [0 x float], ptr %arg2, i64 0, i64 -1
+ br label %bb175
+
+bb175: ; preds = %bb175, %bb
+ %i176 = phi i64 [ %i237, %bb175 ], [ 1, %bb ]
+ %i177 = phi float [ %i198, %bb175 ], [ 0.000000e+00, %bb ]
+ %i184 = shl i64 %i176, 2
+ %i185 = getelementptr %0, ptr %i21, i64 %i176, i32 0
+ %i186 = load float, ptr %i185, align 4
+ %uglygep = getelementptr i8, ptr null, i64 %i184
+ %uglygep2 = getelementptr i8, ptr %uglygep, i64 4
+ %i190 = load float, ptr %uglygep2, align 4
+ %i193 = load float, ptr %uglygep, align 4
+ %i194 = fmul contract float %i186, %i193
+ %i195 = fadd contract float %i177, %i194
+ %i198 = fsub contract float %i195, %i190
+ %i237 = add nuw nsw i64 %i176, 2
+ %i238 = icmp slt i64 %i237, -1
+ br i1 %i238, label %bb175, label %bb239
+
+bb239: ; preds = %bb175
+ store float %storeval, ptr null, align 4
+ ret void
+}
Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -3471,9 +3471,14 @@
if (const Instruction *Inst = dyn_cast<Instruction>(V)) {
// Look for instructions defined outside the loop.
if (L->contains(Inst)) continue;
- } else if (isa<UndefValue>(V))
+ } else if (isa<UndefValue>(V)) {
// Undef doesn't have a live range, so it doesn't matter.
continue;
+ } else if (const Constant *Const = dyn_cast<Constant>(V)) {
+ // NULL values don't really have a live range. They are just NULL.
+ if (Const->isNullValue())
+ continue;
+ }
for (const Use &U : V->uses()) {
const Instruction *UserInst = dyn_cast<Instruction>(U.getUser());
// Ignore non-instructions.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133426.459824.patch
Type: text/x-patch
Size: 2788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220913/46d6f473/attachment.bin>
More information about the llvm-commits
mailing list