Skip to content

Commit 64bb533

Browse files
committed
Add tests with i8, and add nuw flag to GEP
1 parent 76d8829 commit 64bb533

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

llvm/lib/Target/DirectX/DXILLegalizePass.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ static void fixI8UseChain(Instruction &I,
9898
ElementType = AI->getAllocatedType();
9999
if (auto *GEP = dyn_cast<GetElementPtrInst>(NewOperands[0])) {
100100
ElementType = GEP->getSourceElementType();
101-
if (ElementType->isArrayTy())
102-
ElementType = ElementType->getArrayElementType();
103101
}
102+
if (ElementType->isArrayTy())
103+
ElementType = ElementType->getArrayElementType();
104104
LoadInst *NewLoad = Builder.CreateLoad(ElementType, NewOperands[0]);
105105
ReplacedValues[Load] = NewLoad;
106106
ToRemove.push_back(Load);
@@ -593,7 +593,8 @@ legalizeLoadStoreOnArrayAllocas(Instruction &I,
593593

594594
IRBuilder<> Builder(&I);
595595
Value *Zero = Builder.getInt32(0);
596-
Value *GEP = Builder.CreateInBoundsGEP(Ty, AllocaPtrOp, {Zero, Zero});
596+
Value *GEP = Builder.CreateGEP(Ty, AllocaPtrOp, {Zero, Zero}, "",
597+
GEPNoWrapFlags::all());
597598

598599
Value *NewLoadStore = nullptr;
599600
if (auto *LI = dyn_cast<LoadInst>(&I))

llvm/test/CodeGen/DirectX/legalize-i8.ll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ define i32 @i8_geps_index0() {
127127
; CHECK: [[LOAD:%.*]] = load i32, ptr [[GEP]], align 4
128128
; CHECK-NEXT: ret i32 [[LOAD]]
129129
%1 = alloca [2 x i32], align 8
130-
%2 = getelementptr inbounds nuw i8, ptr %1, i32 0
131-
%3 = load i8, ptr %2
132-
%4 = sext i8 %3 to i32
133-
ret i32 %4
130+
%2 = load i8, ptr %1
131+
%3 = sext i8 %2 to i32
132+
ret i32 %3
134133
}
135134

136135
define i32 @i8_geps_index1() {
@@ -149,11 +148,14 @@ define i32 @i8_geps_index1() {
149148
define i32 @i8_gep_store() {
150149
; CHECK-LABEL: define i32 @i8_gep_store(
151150
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [2 x i32], align 8
151+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds nuw [2 x i32], ptr [[ALLOCA]], i32 0, i32 0
152+
; CHECK-NEXT: store i32 0, ptr [[GEP]], align 4
152153
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds nuw [2 x i32], ptr [[ALLOCA]], i32 0, i32 1
153154
; CHECK-NEXT: store i32 1, ptr [[GEP]], align 4
154155
; CHECK: [[LOAD:%.*]] = load i32, ptr [[GEP]], align 4
155156
; CHECK-NEXT: ret i32 [[LOAD]]
156157
%1 = alloca [2 x i32], align 8
158+
store i8 0, ptr %1
157159
%2 = getelementptr inbounds nuw i8, ptr %1, i32 4
158160
store i8 1, ptr %2
159161
%3 = load i8, ptr %2

llvm/test/CodeGen/DirectX/legalize-load-store-array-alloca.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
define float @load() {
44
; CHECK-LABEL: define float @load
55
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [2 x float], align 4
6-
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [2 x float], ptr [[ALLOCA]], i32 0, i32 0
6+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds nuw [2 x float], ptr [[ALLOCA]], i32 0, i32 0
77
; CHECK-NEXT: [[LOAD:%.*]] = load float, ptr [[GEP]], align 4
88
; CHECK-NEXT: ret float [[LOAD]]
99
%a = alloca [2 x float], align 4
@@ -14,7 +14,7 @@ define float @load() {
1414
define void @store() {
1515
; CHECK-LABEL: define void @store
1616
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [3 x i32], align 4
17-
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [3 x i32], ptr [[ALLOCA]], i32 0, i32 0
17+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds nuw [3 x i32], ptr [[ALLOCA]], i32 0, i32 0
1818
; CHECK-NEXT: store i32 0, ptr [[GEP]], align 4
1919
; CHECK-NEXT: ret void
2020
%a = alloca [3 x i32], align 4

0 commit comments

Comments
 (0)