[llvm] r363784 - [ConstantFolding] Fix assertion failure on non-power-of-two vector load.

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 19 03:28:48 PDT 2019


Author: foad
Date: Wed Jun 19 03:28:48 2019
New Revision: 363784

URL: http://llvm.org/viewvc/llvm-project?rev=363784&view=rev
Log:
[ConstantFolding] Fix assertion failure on non-power-of-two vector load.

Summary:
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.

Reviewers: tpr, arsenm, majnemer, dstuttard

Reviewed By: arsenm

Subscribers: hfinkel, wdng, llvm-commits

Tags: #llvm

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

Modified:
    llvm/trunk/lib/Analysis/ConstantFolding.cpp
    llvm/trunk/test/Transforms/InstSimplify/load.ll

Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=363784&r1=363783&r2=363784&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Wed Jun 19 03:28:48 2019
@@ -515,7 +515,7 @@ Constant *FoldReinterpretLoadFromConstPt
       MapTy = Type::getInt64Ty(C->getContext());
     else if (LoadTy->isVectorTy()) {
       MapTy = PointerType::getIntNTy(C->getContext(),
-                                     DL.getTypeAllocSizeInBits(LoadTy));
+                                     DL.getTypeSizeInBits(LoadTy));
     } else
       return nullptr;
 

Modified: llvm/trunk/test/Transforms/InstSimplify/load.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/load.ll?rev=363784&r1=363783&r2=363784&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/load.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/load.ll Wed Jun 19 03:28:48 2019
@@ -28,3 +28,13 @@ define <8 x i32> @partial_load() {
   %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>
+
+; This does an out of bounds load from the global constant
+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
+}




More information about the llvm-commits mailing list