Skip to content

Commit e299976

Browse files
committed
test case: inferred different alloca types
1 parent f43d6a4 commit e299976

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ static bool hasUndefSource(AnyMemTransferInst *MI) {
114114
return isa<AllocaInst>(Src) && Src->hasOneUse();
115115
}
116116

117-
// Optimistically infer a type from either the Src or Dest.
117+
// Optimistically infer a type from either the Src or Dest. Prefers the Src
118+
// over the Dest type.
118119
//
119-
// Returns the DefaultTy if unable to infer a type, if inferred types
120-
// disagree, or, if inferred type does not match the size of load/store.
120+
// Returns the DefaultTy if unable to infer a type, or, if inferred type does
121+
// not match the size of load/store.
121122
static Type *inferType(const DataLayout &DL, IntegerType *DefaultTy, Value *Src,
122123
Value *Dest) {
123124
Type *SrcTy = nullptr;
@@ -129,9 +130,6 @@ static Type *inferType(const DataLayout &DL, IntegerType *DefaultTy, Value *Src,
129130
if (auto *DestAI = dyn_cast<AllocaInst>(Dest))
130131
DestTy = DestAI->getAllocatedType();
131132

132-
if (SrcTy && DestTy && SrcTy != DestTy)
133-
return DefaultTy; // Unable to infer common type
134-
135133
Type *InferredTy = SrcTy ? SrcTy : DestTy;
136134

137135
if (InferredTy &&

llvm/test/Transforms/InstCombine/memcpy_alloca.ll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,29 @@ define void @test8(ptr %src, ptr %dest) {
105105
ret void
106106
}
107107

108+
; Ensure we don't use alloca type if they don't agree
109+
110+
define double @test9(ptr %src, ptr %dest) {
111+
; CHECK-LABEL: @test9(
112+
; CHECK-NEXT: %[[TEMP:.*]] = alloca double, align 1
113+
; CHECK-NEXT: %[[UNPACK0:.*]] = load i32, ptr %src, align 1
114+
; CHECK-NEXT: %[[SRC_GEP:.*]] = getelementptr inbounds nuw i8, ptr %src, i64 4
115+
; CHECK-NEXT: %[[UNPACK1:.*]] = load i32, ptr %[[SRC_GEP]], align 1
116+
; CHECK-NEXT: store i32 %[[UNPACK0]], ptr %[[TEMP]], align 1
117+
; CHECK-NEXT: %[[TEMP_GEP:.*]] = getelementptr inbounds nuw i8, ptr %[[TEMP]], i64 4
118+
; CHECK-NEXT: store i32 %[[UNPACK1]], ptr %[[TEMP_GEP]], align 1
119+
; CHECK-NEXT: %[[RES:.*]] = load double, ptr %[[TEMP]]
120+
; CHECK-NEXT: ret double %[[RES]]
121+
;
122+
%temp = alloca [2 x i32], align 4
123+
%out = alloca double, align 1
124+
125+
call void @llvm.memcpy.p0.p0.i32(ptr %temp, ptr %src, i32 8, i1 false)
126+
call void @llvm.memcpy.p0.p0.i32(ptr %out, ptr %temp, i32 8, i1 false)
127+
128+
%res = load double, ptr %out
129+
130+
ret double %res
131+
}
132+
108133
declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1)

0 commit comments

Comments
 (0)