[llvm] 8acf74f - [InstCombine][SVE] Bail out of isSafeToLoadUnconditionally for scalable types

Peter Waller via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 13 03:14:09 PDT 2022


Author: Peter Waller
Date: 2022-07-13T10:07:36Z
New Revision: 8acf74fd562619be3218df412b0c1b7d89f6ed30

URL: https://github.com/llvm/llvm-project/commit/8acf74fd562619be3218df412b0c1b7d89f6ed30
DIFF: https://github.com/llvm/llvm-project/commit/8acf74fd562619be3218df412b0c1b7d89f6ed30.diff

LOG: [InstCombine][SVE] Bail out of isSafeToLoadUnconditionally for scalable types

`isSafeToLoadUnconditionally` currently assumes sized types. Bail out for now.
This fixes a TypeSize warning reachable from instcombine via (load (select
cond, ptr, ptr)).

Differential Revision: https://reviews.llvm.org/D129477

Added: 
    

Modified: 
    llvm/lib/Analysis/Loads.cpp
    llvm/test/Transforms/InstCombine/scalable-select.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index bc1d82cf14806..938d950e6da79 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -405,7 +405,10 @@ bool llvm::isSafeToLoadUnconditionally(Value *V, Type *Ty, Align Alignment,
                                        Instruction *ScanFrom,
                                        const DominatorTree *DT,
                                        const TargetLibraryInfo *TLI) {
-  APInt Size(DL.getIndexTypeSizeInBits(V->getType()), DL.getTypeStoreSize(Ty));
+  TypeSize TySize = DL.getTypeStoreSize(Ty);
+  if (TySize.isScalable())
+    return false;
+  APInt Size(DL.getIndexTypeSizeInBits(V->getType()), TySize.getFixedValue());
   return isSafeToLoadUnconditionally(V, Alignment, Size, DL, ScanFrom, DT, TLI);
 }
 

diff  --git a/llvm/test/Transforms/InstCombine/scalable-select.ll b/llvm/test/Transforms/InstCombine/scalable-select.ll
index 5dba48ea34c48..eb7a66a76bbcf 100644
--- a/llvm/test/Transforms/InstCombine/scalable-select.ll
+++ b/llvm/test/Transforms/InstCombine/scalable-select.ll
@@ -15,3 +15,28 @@ define <vscale x 1 x i32> @select_opt(<vscale x 1 x i32> %b, <vscale x 1 x i1> %
   %d = select <vscale x 1 x i1> %m, <vscale x 1 x i32> %c, <vscale x 1 x i32> %b
   ret <vscale x 1 x i32> %d
 }
+
+define <vscale x 2 x i64> @load_scalable_of_selected_ptrs(ptr %p0, ptr %p1, i64 %idx) {
+; CHECK-LABEL: @load_scalable_of_selected_ptrs(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[ARRAYIDX0:%.*]] = getelementptr inbounds i32, ptr [[P0:%.*]], i64 [[IDX:%.*]]
+; CHECK-NEXT:    [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr [[P1:%.*]], i64 [[IDX]]
+; CHECK-NEXT:    [[L0:%.*]] = load i32, ptr [[ARRAYIDX0]], align 4
+; CHECK-NEXT:    [[L1:%.*]] = load i32, ptr [[ARRAYIDX1]], align 4
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[L0]], [[L1]]
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], ptr [[ARRAYIDX0]], ptr [[ARRAYIDX1]]
+; CHECK-NEXT:    [[RET:%.*]] = load <vscale x 2 x i64>, ptr [[SEL]], align 16
+; CHECK-NEXT:    ret <vscale x 2 x i64> [[RET]]
+;
+entry:
+  ; Test introduced in response to a TypeSize warning arising from isSafeToLoadUnconditionally via instcombine.
+  ; deref (p0[0] < p1[0] ? p0 : p1) as <vscale x 2 x i64>.
+  %arrayidx0 = getelementptr inbounds i32, ptr %p0, i64 %idx
+  %arrayidx1 = getelementptr inbounds i32, ptr %p1, i64 %idx
+  %l0 = load i32, ptr %arrayidx0
+  %l1 = load i32, ptr %arrayidx1
+  %cmp = icmp slt i32 %l0, %l1
+  %sel = select i1 %cmp, ptr %arrayidx0, ptr %arrayidx1
+  %ret = load <vscale x 2 x i64>, ptr %sel
+  ret <vscale x 2 x i64> %ret
+}


        


More information about the llvm-commits mailing list