forked from OSchip/llvm-project
[ConstantFold] Check uniform value in ConstantFoldLoadFromConst()
This case is automatically handled if ConstantFoldLoadFromConstPtr() is used. Make sure that ConstantFoldLoadFromConst() also handles it.
This commit is contained in:
parent
235886e174
commit
aba7c3c033
|
@ -671,9 +671,12 @@ Constant *llvm::ConstantFoldLoadFromConst(Constant *C, Type *Ty,
|
|||
|
||||
// Try hard to fold loads from bitcasted strange and non-type-safe things.
|
||||
if (Offset.getMinSignedBits() <= 64)
|
||||
return FoldReinterpretLoadFromConst(C, Ty, Offset.getSExtValue(), DL);
|
||||
if (Constant *Result =
|
||||
FoldReinterpretLoadFromConst(C, Ty, Offset.getSExtValue(), DL))
|
||||
return Result;
|
||||
|
||||
return nullptr;
|
||||
// Try an offset-independent fold of a uniform value.
|
||||
return ConstantFoldLoadFromUniformValue(C, Ty);
|
||||
}
|
||||
|
||||
Constant *llvm::ConstantFoldLoadFromConst(Constant *C, Type *Ty,
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
|
||||
; RUN: opt -S -globalopt < %s | FileCheck %s
|
||||
|
||||
; Make sure that the load from uniform value @g1 succeeds during evaluation.
|
||||
|
||||
@g1 = global [2 x i64*] zeroinitializer
|
||||
@g2 = global i64* inttoptr(i64 1 to i64*)
|
||||
|
||||
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @ctor, i8* null }]
|
||||
|
||||
;.
|
||||
; CHECK: @[[G1:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global [2 x i64*] zeroinitializer
|
||||
; CHECK: @[[G2:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global i64* null
|
||||
; CHECK: @[[LLVM_GLOBAL_CTORS:[a-zA-Z0-9_$"\\.-]+]] = appending global [0 x { i32, void ()*, i8* }] zeroinitializer
|
||||
;.
|
||||
define internal void @ctor() {
|
||||
%v = load i64*, i64** getelementptr ([2 x i64*], [2 x i64*]* @g1, i64 0, i64 1)
|
||||
store i64* %v, i64** @g2
|
||||
ret void
|
||||
}
|
Loading…
Reference in New Issue