llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-llvm-transforms Author: Pedro Lobo (pedroclobo) <details> <summary>Changes</summary> GVN forwards a vector to a load of a different type by casting it to an integer. A `poison` lane makes the whole integer `poison`, even when the load doesn't read that lane. Forwarding the vector through a `bitextract` fixes it, keeping `poison` per lane. A scalar load becomes a `bitextract`: ```diff -%1 = bitcast <4 x i32> %v to i128 -%l = trunc i128 %1 to i64 +%1 = bitcast <4 x i32> %v to b128 +%l = bitextract i64, b128 %1, i32 0 ``` A vector load goes through a byte `bitextract` and a `bitcast`, as `bitextract` can't return a vector: ```diff -%1 = bitcast <4 x i64> %v to i256 -%2 = trunc i256 %1 to i128 -%l = bitcast i128 %2 to <2 x i64> +%1 = bitcast <4 x i64> %v to b256 +%2 = bitextract b128, b256 %1, i32 0 +%l = bitcast b128 %2 to <2 x i64> ``` A load of the same size skips the integer and becomes a direct cast: ```diff -%1 = bitcast <4 x i32> %v to i128 -%l = bitcast i128 %1 to <4 x float> +%l = bitcast <4 x i32> %v to <4 x float> ``` This fixes the example in the description of #<!-- -->99268, but not the partial lane case. Forwarding from an earlier load can still make a value more `poison`, when the later load reads only part of a lane: ```llvm %v = load <4 x i32>, ptr %p ; byte 1 is poison, so lane 0 is poison call void @<!-- -->use(<4 x i32> %v) %x = load i8, ptr %p ; byte 0 is defined ``` GVN forwards `%v` to `%x`. `%x` reads only byte 0, but it takes lane 0 of `%v`, which is `poison`: ```diff -%x = load i8, ptr %p +%1 = bitcast <4 x i32> %v to b128 +%x = bitextract i8, b128 %1, i32 0 ``` This will be addressed in a follow-up. Fixes #<!-- -->209935. --- Patch is 25.50 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/237784.diff 5 Files Affected: - (modified) llvm/lib/Transforms/Utils/VNCoercion.cpp (+12-6) - (modified) llvm/test/Transforms/GVN/pr14166.ll (-1) - (modified) llvm/test/Transforms/GVN/pr63059.ll (+48-63) - (modified) llvm/test/Transforms/GVN/ptr-vector-coercion.ll (+4-9) - (added) llvm/test/Transforms/GVN/vector-poison.ll (+225) ``````````diff diff --git a/llvm/lib/Transforms/Utils/VNCoercion.cpp b/llvm/lib/Transforms/Utils/VNCoercion.cpp index b002bf76a233c5..f8b3a67cc15745 100644 --- a/llvm/lib/Transforms/Utils/VNCoercion.cpp +++ b/llvm/lib/Transforms/Utils/VNCoercion.cpp @@ -362,10 +362,16 @@ static Value *getStoreValueForLoadHelper(Value *SrcVal, unsigned Offset, ShiftAmt = (StoreSize - LoadSize - Offset) * 8; // Integers drop provenance, and one poison bit poisons the whole value. + // A vector tracks poison per lane. if (SrcTy->isByteOrByteVectorTy() || - (SrcTy->isPtrOrPtrVectorTy() && LoadTy->isByteOrByteVectorTy())) { + (SrcTy->isPtrOrPtrVectorTy() && LoadTy->isByteOrByteVectorTy()) || + (SrcTy->isVectorTy() && LoadSize != StoreSize)) { unsigned SrcBits = DL.getTypeSizeInBits(SrcTy).getFixedValue(); unsigned LoadBits = DL.getTypeSizeInBits(LoadTy).getFixedValue(); + // Fold a constant bitextract, as the builder has no DataLayout. + if (auto *C = dyn_cast<Constant>(SrcVal)) + if (Constant *Res = getConstantValueForLoad(C, Offset, LoadTy, DL)) + return Res; if (LoadBits == SrcBits) return Builder.CreateBitCast(SrcVal, LoadTy); // bitextract needs a scalar byte source and can't return a vector. @@ -382,6 +388,10 @@ static Value *getStoreValueForLoadHelper(Value *SrcVal, unsigned Offset, if (SrcVal->getType()->isPtrOrPtrVectorTy()) SrcVal = Builder.CreatePtrToInt(SrcVal, DL.getIntPtrType(SrcVal->getType())); + // If the load and store are the same size, there is nothing to shift. + // If one lane of a vector is poison, an integer cast would poison all lanes. + if (LoadSize == StoreSize) + return SrcVal; if (!SrcVal->getType()->isIntegerTy()) SrcVal = Builder.CreateBitCast(SrcVal, IntegerType::get(Ctx, StoreSize * 8)); @@ -389,11 +399,7 @@ static Value *getStoreValueForLoadHelper(Value *SrcVal, unsigned Offset, if (ShiftAmt) SrcVal = Builder.CreateLShr(SrcVal, ConstantInt::get(SrcVal->getType(), ShiftAmt)); - - if (LoadSize != StoreSize) - SrcVal = Builder.CreateTruncOrBitCast(SrcVal, - IntegerType::get(Ctx, LoadSize * 8)); - return SrcVal; + return Builder.CreateTrunc(SrcVal, IntegerType::get(Ctx, LoadSize * 8)); } Value *VNCoercion::getValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy, diff --git a/llvm/test/Transforms/GVN/pr14166.ll b/llvm/test/Transforms/GVN/pr14166.ll index e9d1e4db088bb7..2dd7c1ef02d154 100644 --- a/llvm/test/Transforms/GVN/pr14166.ll +++ b/llvm/test/Transforms/GVN/pr14166.ll @@ -9,7 +9,6 @@ define <2 x i32> @test1() { ; CHECK-NEXT: [[V2:%.*]] = load <2 x i32>, ptr [[V1]], align 8 ; CHECK-NEXT: [[V3:%.*]] = inttoptr <2 x i32> [[V2]] to <2 x ptr> ; CHECK-NEXT: store <2 x ptr> [[V3]], ptr [[V1]], align 8 -; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i32> [[V2]] to i64 ; CHECK-NEXT: ret <2 x i32> [[V2]] ; %v1 = alloca <2 x i32> diff --git a/llvm/test/Transforms/GVN/pr63059.ll b/llvm/test/Transforms/GVN/pr63059.ll index 3d267f7aa7a50d..2a0038589a2c39 100644 --- a/llvm/test/Transforms/GVN/pr63059.ll +++ b/llvm/test/Transforms/GVN/pr63059.ll @@ -8,17 +8,13 @@ define <4 x float> @ConvertVectors_ByRef(ptr %loc) { ; CHECK-NEXT: [[LOAD_VEC:%.*]] = load <4 x float>, ptr [[LOC]], align 16 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x float> [[LOAD_VEC]], <4 x float> poison, <4 x i32> <i32 0, i32 poison, i32 poison, i32 poison> ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [4 x float], ptr [[LOC]], i64 0, i64 1 -; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x float> [[LOAD_VEC]] to i128 -; CHECK-NEXT: [[TMP2:%.*]] = lshr i128 [[TMP1]], 32 -; CHECK-NEXT: [[TMP3:%.*]] = trunc i128 [[TMP2]] to i32 -; CHECK-NEXT: [[TMP4:%.*]] = bitcast i32 [[TMP3]] to float -; CHECK-NEXT: [[INS1:%.*]] = insertelement <4 x float> [[SHUF]], float [[TMP4]], i64 1 +; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x float> [[LOAD_VEC]] to b128 +; CHECK-NEXT: [[TMP2:%.*]] = bitextract float, b128 [[TMP1]], i32 32 +; CHECK-NEXT: [[INS1:%.*]] = insertelement <4 x float> [[SHUF]], float [[TMP2]], i64 1 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [4 x float], ptr [[LOC]], i64 0, i64 2 -; CHECK-NEXT: [[TMP5:%.*]] = lshr i128 [[TMP1]], 64 -; CHECK-NEXT: [[TMP6:%.*]] = trunc i128 [[TMP5]] to i32 -; CHECK-NEXT: [[TMP7:%.*]] = bitcast i32 [[TMP6]] to float -; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> [[INS1]], float [[TMP7]], i64 2 -; CHECK-NEXT: [[INS3:%.*]] = insertelement <4 x float> [[INS2]], float [[TMP7]], i64 3 +; CHECK-NEXT: [[TMP3:%.*]] = bitextract float, b128 [[TMP1]], i32 64 +; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> [[INS1]], float [[TMP3]], i64 2 +; CHECK-NEXT: [[INS3:%.*]] = insertelement <4 x float> [[INS2]], float [[TMP3]], i64 3 ; CHECK-NEXT: ret <4 x float> [[INS3]] ; %load_vec = load <4 x float>, ptr %loc, align 16 @@ -39,10 +35,9 @@ define i64 @store_element_smaller_than_load(ptr %loc, <4 x i32> %v) { ; CHECK-NEXT: entry: ; CHECK-NEXT: store <4 x i32> [[V]], ptr [[LOC]], align 16 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [4 x i32], ptr [[LOC]], i64 0, i64 2 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to i128 -; CHECK-NEXT: [[TMP1:%.*]] = lshr i128 [[TMP0]], 64 -; CHECK-NEXT: [[TMP2:%.*]] = trunc i128 [[TMP1]] to i64 -; CHECK-NEXT: ret i64 [[TMP2]] +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to b128 +; CHECK-NEXT: [[TMP1:%.*]] = bitextract i64, b128 [[TMP0]], i32 64 +; CHECK-NEXT: ret i64 [[TMP1]] ; entry: store <4 x i32> %v, ptr %loc @@ -76,10 +71,9 @@ define i64 @call_before_load_memory_none(ptr %loc, <4 x i32> %v) { ; CHECK-NEXT: store <4 x i32> [[V]], ptr [[LOC]], align 16 ; CHECK-NEXT: call void @f_no_mem(<4 x i32> [[V]]) ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [4 x i32], ptr [[LOC]], i64 0, i64 2 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to i128 -; CHECK-NEXT: [[TMP1:%.*]] = lshr i128 [[TMP0]], 64 -; CHECK-NEXT: [[TMP2:%.*]] = trunc i128 [[TMP1]] to i64 -; CHECK-NEXT: ret i64 [[TMP2]] +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to b128 +; CHECK-NEXT: [[TMP1:%.*]] = bitextract i64, b128 [[TMP0]], i32 64 +; CHECK-NEXT: ret i64 [[TMP1]] ; entry: store <4 x i32> %v, ptr %loc @@ -95,11 +89,10 @@ define i64 @call_after_load(ptr %loc, <4 x i32> %v) { ; CHECK-NEXT: entry: ; CHECK-NEXT: store <4 x i32> [[V]], ptr [[LOC]], align 16 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [4 x i32], ptr [[LOC]], i64 0, i64 2 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to i128 -; CHECK-NEXT: [[TMP1:%.*]] = lshr i128 [[TMP0]], 64 -; CHECK-NEXT: [[TMP2:%.*]] = trunc i128 [[TMP1]] to i64 +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to b128 +; CHECK-NEXT: [[TMP1:%.*]] = bitextract i64, b128 [[TMP0]], i32 64 ; CHECK-NEXT: call void @f(<4 x i32> [[V]]) -; CHECK-NEXT: ret i64 [[TMP2]] +; CHECK-NEXT: ret i64 [[TMP1]] ; entry: store <4 x i32> %v, ptr %loc @@ -114,11 +107,9 @@ define double @store_element_smaller_than_load_float(ptr %loc, <4 x float> %v) { ; CHECK-SAME: (ptr [[LOC:%.*]], <4 x float> [[V:%.*]]) { ; CHECK-NEXT: store <4 x float> [[V]], ptr [[LOC]], align 16 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [4 x float], ptr [[LOC]], i64 0, i64 2 -; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x float> [[V]] to i128 -; CHECK-NEXT: [[TMP2:%.*]] = lshr i128 [[TMP1]], 64 -; CHECK-NEXT: [[TMP3:%.*]] = trunc i128 [[TMP2]] to i64 -; CHECK-NEXT: [[TMP4:%.*]] = bitcast i64 [[TMP3]] to double -; CHECK-NEXT: ret double [[TMP4]] +; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x float> [[V]] to b128 +; CHECK-NEXT: [[TMP2:%.*]] = bitextract double, b128 [[TMP1]], i32 64 +; CHECK-NEXT: ret double [[TMP2]] ; store <4 x float> %v, ptr %loc %gep = getelementptr inbounds [4 x float], ptr %loc, i64 0, i64 2 @@ -144,10 +135,9 @@ define i9 @load_as_scalar_larger(ptr %loc, <4 x i6> %v) { ; CHECK-LABEL: define i9 @load_as_scalar_larger ; CHECK-SAME: (ptr [[LOC:%.*]], <4 x i6> [[V:%.*]]) { ; CHECK-NEXT: store <4 x i6> [[V]], ptr [[LOC]], align 4 -; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i6> [[V]] to i24 -; CHECK-NEXT: [[TMP2:%.*]] = trunc i24 [[TMP1]] to i16 -; CHECK-NEXT: [[TMP3:%.*]] = trunc i16 [[TMP2]] to i9 -; CHECK-NEXT: ret i9 [[TMP3]] +; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i6> [[V]] to b24 +; CHECK-NEXT: [[TMP2:%.*]] = bitextract i9, b24 [[TMP1]], i32 0 +; CHECK-NEXT: ret i9 [[TMP2]] ; store <4 x i6> %v, ptr %loc %gep = getelementptr i9, ptr %loc, i64 0 @@ -160,10 +150,9 @@ define i4 @load_as_scalar_smaller(ptr %loc, <4 x i6> %v) { ; CHECK-LABEL: define i4 @load_as_scalar_smaller ; CHECK-SAME: (ptr [[LOC:%.*]], <4 x i6> [[V:%.*]]) { ; CHECK-NEXT: store <4 x i6> [[V]], ptr [[LOC]], align 4 -; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i6> [[V]] to i24 -; CHECK-NEXT: [[TMP2:%.*]] = trunc i24 [[TMP1]] to i8 -; CHECK-NEXT: [[TMP3:%.*]] = trunc i8 [[TMP2]] to i4 -; CHECK-NEXT: ret i4 [[TMP3]] +; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i6> [[V]] to b24 +; CHECK-NEXT: [[TMP2:%.*]] = bitextract i4, b24 [[TMP1]], i32 0 +; CHECK-NEXT: ret i4 [[TMP2]] ; store <4 x i6> %v, ptr %loc %gep = getelementptr i4, ptr %loc, i64 0 @@ -193,9 +182,8 @@ define i64 @load_vec_same_size_different_type1(ptr %loc, <4 x i32> %v) { ; CHECK-SAME: (ptr [[LOC:%.*]], <4 x i32> [[V:%.*]]) { ; CHECK-NEXT: entry: ; CHECK-NEXT: store <4 x i32> [[V]], ptr [[LOC]], align 16 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to i128 -; CHECK-NEXT: [[TMP1:%.*]] = bitcast i128 [[TMP0]] to <2 x i64> -; CHECK-NEXT: [[R:%.*]] = extractelement <2 x i64> [[TMP1]], i32 1 +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to <2 x i64> +; CHECK-NEXT: [[R:%.*]] = extractelement <2 x i64> [[TMP0]], i32 1 ; CHECK-NEXT: ret i64 [[R]] ; entry: @@ -211,9 +199,8 @@ define double @load_vec_same_size_different_type2(ptr %loc, <4 x i32> %v) { ; CHECK-SAME: (ptr [[LOC:%.*]], <4 x i32> [[V:%.*]]) { ; CHECK-NEXT: entry: ; CHECK-NEXT: store <4 x i32> [[V]], ptr [[LOC]], align 16 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to i128 -; CHECK-NEXT: [[TMP1:%.*]] = bitcast i128 [[TMP0]] to <2 x double> -; CHECK-NEXT: [[R:%.*]] = extractelement <2 x double> [[TMP1]], i32 1 +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to <2 x double> +; CHECK-NEXT: [[R:%.*]] = extractelement <2 x double> [[TMP0]], i32 1 ; CHECK-NEXT: ret double [[R]] ; entry: @@ -229,9 +216,9 @@ define i32 @load_subvector_same_type(ptr %loc, <4 x i32> %v) { ; CHECK-SAME: (ptr [[LOC:%.*]], <4 x i32> [[V:%.*]]) { ; CHECK-NEXT: entry: ; CHECK-NEXT: store <4 x i32> [[V]], ptr [[LOC]], align 16 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to i128 -; CHECK-NEXT: [[TMP1:%.*]] = trunc i128 [[TMP0]] to i64 -; CHECK-NEXT: [[TMP2:%.*]] = bitcast i64 [[TMP1]] to <2 x i32> +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to b128 +; CHECK-NEXT: [[TMP1:%.*]] = bitextract b64, b128 [[TMP0]], i32 0 +; CHECK-NEXT: [[TMP2:%.*]] = bitcast b64 [[TMP1]] to <2 x i32> ; CHECK-NEXT: [[R:%.*]] = extractelement <2 x i32> [[TMP2]], i32 1 ; CHECK-NEXT: ret i32 [[R]] ; @@ -248,9 +235,9 @@ define i64 @load_subvector_different_type(ptr %loc, <8 x i32> %v) { ; CHECK-SAME: (ptr [[LOC:%.*]], <8 x i32> [[V:%.*]]) { ; CHECK-NEXT: entry: ; CHECK-NEXT: store <8 x i32> [[V]], ptr [[LOC]], align 32 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i32> [[V]] to i256 -; CHECK-NEXT: [[TMP1:%.*]] = trunc i256 [[TMP0]] to i128 -; CHECK-NEXT: [[TMP2:%.*]] = bitcast i128 [[TMP1]] to <2 x i64> +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i32> [[V]] to b256 +; CHECK-NEXT: [[TMP1:%.*]] = bitextract b128, b256 [[TMP0]], i32 0 +; CHECK-NEXT: [[TMP2:%.*]] = bitcast b128 [[TMP1]] to <2 x i64> ; CHECK-NEXT: [[R:%.*]] = extractelement <2 x i64> [[TMP2]], i32 1 ; CHECK-NEXT: ret i64 [[R]] ; @@ -267,9 +254,9 @@ define i16 @load_subvector_different_type2(ptr %loc, <8 x i32> %v) { ; CHECK-SAME: (ptr [[LOC:%.*]], <8 x i32> [[V:%.*]]) { ; CHECK-NEXT: entry: ; CHECK-NEXT: store <8 x i32> [[V]], ptr [[LOC]], align 32 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i32> [[V]] to i256 -; CHECK-NEXT: [[TMP1:%.*]] = trunc i256 [[TMP0]] to i32 -; CHECK-NEXT: [[TMP2:%.*]] = bitcast i32 [[TMP1]] to <2 x i16> +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i32> [[V]] to b256 +; CHECK-NEXT: [[TMP1:%.*]] = bitextract b32, b256 [[TMP0]], i32 0 +; CHECK-NEXT: [[TMP2:%.*]] = bitcast b32 [[TMP1]] to <2 x i16> ; CHECK-NEXT: [[R:%.*]] = extractelement <2 x i16> [[TMP2]], i32 1 ; CHECK-NEXT: ret i16 [[R]] ; @@ -286,11 +273,10 @@ define i4 @load_subvector_different_type3(ptr %loc, <8 x i8> %v) { ; CHECK-SAME: (ptr [[LOC:%.*]], <8 x i8> [[V:%.*]]) { ; CHECK-NEXT: entry: ; CHECK-NEXT: store <8 x i8> [[V]], ptr [[LOC]], align 8 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i8> [[V]] to i64 -; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[TMP0]] to i16 -; CHECK-NEXT: [[TMP2:%.*]] = trunc i16 [[TMP1]] to i12 -; CHECK-NEXT: [[TMP3:%.*]] = bitcast i12 [[TMP2]] to <3 x i4> -; CHECK-NEXT: [[R:%.*]] = extractelement <3 x i4> [[TMP3]], i32 1 +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i8> [[V]] to b64 +; CHECK-NEXT: [[TMP1:%.*]] = bitextract b12, b64 [[TMP0]], i32 0 +; CHECK-NEXT: [[TMP2:%.*]] = bitcast b12 [[TMP1]] to <3 x i4> +; CHECK-NEXT: [[R:%.*]] = extractelement <3 x i4> [[TMP2]], i32 1 ; CHECK-NEXT: ret i4 [[R]] ; entry: @@ -306,9 +292,9 @@ define i12 @load_subvector_different_type4(ptr %loc, <8 x i8> %v) { ; CHECK-SAME: (ptr [[LOC:%.*]], <8 x i8> [[V:%.*]]) { ; CHECK-NEXT: entry: ; CHECK-NEXT: store <8 x i8> [[V]], ptr [[LOC]], align 8 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i8> [[V]] to i64 -; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[TMP0]] to i24 -; CHECK-NEXT: [[TMP2:%.*]] = bitcast i24 [[TMP1]] to <2 x i12> +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i8> [[V]] to b64 +; CHECK-NEXT: [[TMP1:%.*]] = bitextract b24, b64 [[TMP0]], i32 0 +; CHECK-NEXT: [[TMP2:%.*]] = bitcast b24 [[TMP1]] to <2 x i12> ; CHECK-NEXT: [[R:%.*]] = extractelement <2 x i12> [[TMP2]], i32 1 ; CHECK-NEXT: ret i12 [[R]] ; @@ -325,11 +311,10 @@ define i6 @load_subvector_different_type5(ptr %loc, <8 x i8> %v) { ; CHECK-SAME: (ptr [[LOC:%.*]], <8 x i8> [[V:%.*]]) { ; CHECK-NEXT: entry: ; CHECK-NEXT: store <8 x i8> [[V]], ptr [[LOC]], align 8 -; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i8> [[V]] to i64 -; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[TMP0]] to i16 -; CHECK-NEXT: [[TMP2:%.*]] = trunc i16 [[TMP1]] to i12 -; CHECK-NEXT: [[TMP3:%.*]] = bitcast i12 [[TMP2]] to <2 x i6> -; CHECK-NEXT: [[R:%.*]] = extractelement <2 x i6> [[TMP3]], i32 1 +; CHECK-NEXT: [[TMP0:%.*]] = bitcast <8 x i8> [[V]] to b64 +; CHECK-NEXT: [[TMP1:%.*]] = bitextract b12, b64 [[TMP0]], i32 0 +; CHECK-NEXT: [[TMP2:%.*]] = bitcast b12 [[TMP1]] to <2 x i6> +; CHECK-NEXT: [[R:%.*]] = extractelement <2 x i6> [[TMP2]], i32 1 ; CHECK-NEXT: ret i6 [[R]] ; entry: diff --git a/llvm/test/Transforms/GVN/ptr-vector-coercion.ll b/llvm/test/Transforms/GVN/ptr-vector-coercion.ll index 9544b52927bec6..c368b978927833 100644 --- a/llvm/test/Transforms/GVN/ptr-vector-coercion.ll +++ b/llvm/test/Transforms/GVN/ptr-vector-coercion.ll @@ -56,17 +56,12 @@ define <1 x ptr> @neg_ptr1_store_to_v1ptr_load(ptr %p, ptr addrspace(1) %v) { ret <1 x ptr> %l } -; Pointers of different sizes can't be bitcast to each other. -; FIXME: Going through integers drops provenance, and a poison lane in %v -; poisons the loaded pointer. -define ptr @neg_v2ptr_store_to_ptr_load(ptr %p, <2 x ptr> %v) { -; CHECK-LABEL: define ptr @neg_v2ptr_store_to_ptr_load( +define ptr @v2ptr_store_to_ptr_load(ptr %p, <2 x ptr> %v) { +; CHECK-LABEL: define ptr @v2ptr_store_to_ptr_load( ; CHECK-SAME: ptr [[P:%.*]], <2 x ptr> [[V:%.*]]) { ; CHECK-NEXT: store <2 x ptr> [[V]], ptr [[P]], align 16 -; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint <2 x ptr> [[V]] to <2 x i64> -; CHECK-NEXT: [[TMP2:%.*]] = bitcast <2 x i64> [[TMP1]] to i128 -; CHECK-NEXT: [[TMP3:%.*]] = trunc i128 [[TMP2]] to i64 -; CHECK-NEXT: [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr +; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x ptr> [[V]] to b128 +; CHECK-NEXT: [[TMP4:%.*]] = bitextract ptr, b128 [[TMP1]], i32 0 ; CHECK-NEXT: ret ptr [[TMP4]] ; store <2 x ptr> %v, ptr %p diff --git a/llvm/test/Transforms/GVN/vector-poison.ll b/llvm/test/Transforms/GVN/vector-poison.ll new file mode 100644 index 00000000000000..35dc67a4511aa1 --- /dev/null +++ b/llvm/test/Transforms/GVN/vector-poison.ll @@ -0,0 +1,225 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 +; RUN: opt < %s -data-layout="e-p:64:64:64-p1:32:32:32-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-n8:16:32:64" -passes=gvn -S | FileCheck %s --check-prefixes=CHECK,LE +; RUN: opt < %s -data-layout="E-p:64:64:64-p1:32:32:32-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-n8:16:32:64" -passes=gvn -S | FileCheck %s --check-prefixes=CHECK,BE + +; Vectors track poison per lane, while integers track poison per value (either +; the whole integer is valid, or it is poison). + +define i64 @pr99268(ptr %p, i1 %c) { +; LE-LABEL: define i64 @pr99268( +; LE-SAME: ptr [[P:%.*]], i1 [[C:%.*]]) { +; LE-NEXT: [[ENTRY:.*:]] +; LE-NEXT: br i1 [[C]], label %[[THEN:.*]], label %[[ELSE:.*]] +; LE: [[THEN]]: +; LE-NEXT: [[V:%.*]] = load <4 x i32>, ptr [[P]], align 16 +; LE-NEXT: call void @use(<4 x i32> [[V]]) +; LE-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to b128 +; LE-NEXT: [[TMP1:%.*]] = bitextract i64, b128 [[TMP0]], i32 0 +; LE-NEXT: br label %[[EXIT:.*]] +; LE: [[ELSE]]: +; LE-NEXT: [[L_PRE:%.*]] = load i64, ptr [[P]], align 4 +; LE-NEXT: br label %[[EXIT]] +; LE: [[EXIT]]: +; LE-NEXT: [[L:%.*]] = phi i64 [ [[L_PRE]], %[[ELSE]] ], [ [[TMP1]], %[[THEN]] ] +; LE-NEXT: ret i64 [[L]] +; +; BE-LABEL: define i64 @pr99268( +; BE-SAME: ptr [[P:%.*]], i1 [[C:%.*]]) { +; BE-NEXT: [[ENTRY:.*:]] +; BE-NEXT: br i1 [[C]], label %[[THEN:.*]], label %[[ELSE:.*]] +; BE: [[THEN]]: +; BE-NEXT: [[V:%.*]] = load <4 x i32>, ptr [[P]], align 16 +; BE-NEXT: call void @use(<4 x i32> [[V]]) +; BE-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[V]] to b128 +; BE-NEXT: [[TMP1:%.*]] = bitextract i64, b128 [[TMP0]], i32 64 +; BE-NEXT: br label %[[EXIT:.*]] +; BE: [[ELSE]]: +; BE-NEXT: [[L_PRE:%.*]] = load i64, ptr [[P]], align 4 +; BE-NEXT: br label %[[EXIT]] +; BE: [[EXIT]]: +; BE-NEXT: [[L:%.*]] = phi i64 [ [[L_PRE]], %[[ELSE]] ], [ [[TMP1]], %[[THEN]] ] +; BE-NEXT: ret i64 [[L]] +; +entry: + br i1 %c, label %then, label %else + +then: + %v = load <4 x i32>, ptr %p, align 16 + call void @use(<4 x i32> %v) + br label %exit + +else: + br label %exit + +exit: + %l = load i64, ptr %p, align 4 + ret i64 %l +} + +define <2 x i64> @pr209935(<4 x i64> %v, ptr %p) { +; LE-LABEL: define <2 x i64> @pr209935( +; LE-SAME: <4 x i64> [[V:%.*]], ptr [[P:%.*]]) { +; LE-NEXT: store <4 x i64> [[V]], ptr [[P]], align 8 +; LE-NEXT: [[TMP1:%.*]] = bitcast <4 x i64> [[V]] to b256 +; LE-NEXT: [[TMP2:%.*]] = bitextract b128, b256 [[TMP1]], i32 0 +; LE-NEXT: [[TMP3:%.*]] = bitcast b128 [[TMP2]] to <2 x i64> +; LE-NEXT: ret <2 x i64> [[TMP3]] +; +; BE-LABEL: define <2 x i64> @pr209935( +; BE-SAME: <4 x i64> [[V:%.*]], ptr [[P:%.*]]) { +; BE-NEXT: store <4 x i64> [[V]], ptr [[P]], align 8 +; BE-NEXT: [[TMP1:%.*]] = bitcast <4 x i64> [[V]] to b256 +; BE-NEXT: [[TMP2:%.*]] = bitextract b128, b256 [[TMP1]], i32 128 +; BE-NEXT: [[TMP4:%.*]] = bitcast b128 [[TMP2]] to <2 x i64> +; BE-NEXT: ret <2 x i64> [[TMP4]] +; + store <4 x i64> %v, ptr %p, align 8 + %l = load <2 x i64>, ptr %p, align 8 + ret <2 x i64> %l +} + +define i16 @store_v4i32_to_i16_straddle(<4 x i32> %v, ptr %p) { +; LE-LABEL: define i16 @store_v4i32_to_i16_straddle( +; LE-SAME: <4 x i32> [[V:%.*]], ptr [[P:%.*]]) { +; LE-NEXT: store <4 x i32> [[V]], ptr [[P]], align 16 +; LE-NEXT: [[Q:%.*]] = getelementptr i8, ptr [[P]], i6... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/237784 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
