[PATCH] D63375: [ConstantFolding] Fix assertion failure on non-power-of-two vector load.

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 15 06:49:25 PDT 2019


foad created this revision.
foad added reviewers: tpr, arsenm, majnemer, dstuttard.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

The test case does an (out of bounds) load from a global constant with
type <3 x float>. InstSimplify tried to turn this into an integer load
of the whole alloc size of the vector, which is 128 bits due to
alignment padding, and then bitcast this to <3 x vector> which failed
an assertion due to the type size mismatch.

The fix is to do an integer load of the normal size of the vector, with
no alignment padding.

Change-Id: I911d744b6f048fb18df5814dfef21a9d8259aeb6


Repository:
  rL LLVM

https://reviews.llvm.org/D63375

Files:
  lib/Analysis/ConstantFolding.cpp
  test/Transforms/InstSimplify/load.ll


Index: test/Transforms/InstSimplify/load.ll
===================================================================
--- test/Transforms/InstSimplify/load.ll
+++ test/Transforms/InstSimplify/load.ll
@@ -28,3 +28,12 @@
   %load = load <8 x i32>, <8 x i32>* bitcast (i32* getelementptr ([8 x i32], [8 x i32]* @GV, i64 0, i64 -1) to <8 x i32>*)
   ret <8 x i32> %load
 }
+
+ at constvec = internal constant <3 x float> <float 0xBFDA20BC40000000, float 0xBFE6A09EE0000000, float 0x3FE279A760000000>
+
+define <3 x float> @load_vec3() {
+; CHECK-LABEL: @load_vec3(
+; CHECK-NEXT:    ret <3 x float> undef
+  %1 = load <3 x float>, <3 x float>* getelementptr inbounds (<3 x float>, <3 x float>* @constvec, i64 1)
+  ret <3 x float> %1
+}
Index: lib/Analysis/ConstantFolding.cpp
===================================================================
--- lib/Analysis/ConstantFolding.cpp
+++ lib/Analysis/ConstantFolding.cpp
@@ -515,7 +515,7 @@
       MapTy = Type::getInt64Ty(C->getContext());
     else if (LoadTy->isVectorTy()) {
       MapTy = PointerType::getIntNTy(C->getContext(),
-                                     DL.getTypeAllocSizeInBits(LoadTy));
+                                     DL.getTypeSizeInBits(LoadTy));
     } else
       return nullptr;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63375.204915.patch
Type: text/x-patch
Size: 1249 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190615/1f133c75/attachment.bin>


More information about the llvm-commits mailing list