forked from OSchip/llvm-project
[GlobalOpt] Fix global to select transform under opaque pointers
We need to check that the load/store type is also the same, as this is no longer implicitly checked through the pointer type.
This commit is contained in:
parent
97ef15ad76
commit
1cbb456123
|
@ -1252,9 +1252,12 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
|
|||
|
||||
// Walk the use list of the global seeing if all the uses are load or store.
|
||||
// If there is anything else, bail out.
|
||||
for (User *U : GV->users())
|
||||
for (User *U : GV->users()) {
|
||||
if (!isa<LoadInst>(U) && !isa<StoreInst>(U))
|
||||
return false;
|
||||
if (getLoadStoreType(U) != GVElType)
|
||||
return false;
|
||||
}
|
||||
|
||||
LLVM_DEBUG(dbgs() << " *** SHRINKING TO BOOL: " << *GV << "\n");
|
||||
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt -S -globalopt -opaque-pointers < %s | FileCheck %s
|
||||
|
||||
; Make sure we don't try to convert to select if the load/stores don't match
|
||||
; the global type.
|
||||
|
||||
@g1 = internal global i64 zeroinitializer
|
||||
@g2 = internal global i64 zeroinitializer
|
||||
@g3 = internal global i64 zeroinitializer
|
||||
|
||||
define void @store1() {
|
||||
; CHECK-LABEL: @store1(
|
||||
; CHECK-NEXT: store i32 2, ptr @g1, align 4
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
store i32 2, ptr @g1
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @load1() {
|
||||
; CHECK-LABEL: @load1(
|
||||
; CHECK-NEXT: [[V:%.*]] = load i32, ptr @g1, align 4
|
||||
; CHECK-NEXT: ret i32 [[V]]
|
||||
;
|
||||
%v = load i32, ptr @g1
|
||||
ret i32 %v
|
||||
}
|
||||
|
||||
define void @store2() {
|
||||
; CHECK-LABEL: @store2(
|
||||
; CHECK-NEXT: store i64 2, ptr @g2, align 4
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
store i64 2, ptr @g2
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @load2() {
|
||||
; CHECK-LABEL: @load2(
|
||||
; CHECK-NEXT: [[V:%.*]] = load i32, ptr @g2, align 4
|
||||
; CHECK-NEXT: ret i32 [[V]]
|
||||
;
|
||||
%v = load i32, ptr @g2
|
||||
ret i32 %v
|
||||
}
|
||||
|
||||
define void @store3() {
|
||||
; CHECK-LABEL: @store3(
|
||||
; CHECK-NEXT: store i1 true, ptr @g3, align 1
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
store i64 2, ptr @g3
|
||||
ret void
|
||||
}
|
||||
|
||||
define i64 @load3() {
|
||||
; CHECK-LABEL: @load3(
|
||||
; CHECK-NEXT: [[V_B:%.*]] = load i1, ptr @g3, align 1
|
||||
; CHECK-NEXT: [[V:%.*]] = select i1 [[V_B]], i64 2, i64 0
|
||||
; CHECK-NEXT: ret i64 [[V]]
|
||||
;
|
||||
%v = load i64, ptr @g3
|
||||
ret i64 %v
|
||||
}
|
Loading…
Reference in New Issue