Index: lib/Analysis/ConstantFolding.cpp =================================================================== --- lib/Analysis/ConstantFolding.cpp +++ lib/Analysis/ConstantFolding.cpp @@ -295,9 +295,10 @@ auto *CE = dyn_cast(C); if (!CE) return false; - // Look through ptr->int and ptr->ptr casts. + // Look through ptr->int, ptr->ptr casts and address space casts. if (CE->getOpcode() == Instruction::PtrToInt || - CE->getOpcode() == Instruction::BitCast) + CE->getOpcode() == Instruction::BitCast || + CE->getOpcode() == Instruction::AddrSpaceCast) return IsConstantOffsetFromGlobal(CE->getOperand(0), GV, Offset, DL); // i32* getelementptr ([5 x i32]* @a, i32 0, i32 5) Index: test/Transforms/ConstProp/loads.ll =================================================================== --- test/Transforms/ConstProp/loads.ll +++ test/Transforms/ConstProp/loads.ll @@ -40,16 +40,13 @@ %r = load i16, i16 addrspace(1)* addrspacecast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16 addrspace(1)*) ret i16 %r -; FIXME: Should be able to load through a constant addrspacecast. ; 0xBEEF ; LE-LABEL: @test2_addrspacecast( -; XLE: ret i16 -16657 -; LE: load i16, i16 addrspace(1)* addrspacecast +; LE: ret i16 -16657 ; 0xDEAD ; BE-LABEL: @test2_addrspacecast( -; XBE: ret i16 -8531 -; BE: load i16, i16 addrspace(1)* addrspacecast +; BE: ret i16 -8531 } ; Load of second 16 bits of 32-bit value.