Index: llvm/lib/Analysis/ConstantFolding.cpp =================================================================== --- llvm/lib/Analysis/ConstantFolding.cpp +++ llvm/lib/Analysis/ConstantFolding.cpp @@ -429,18 +429,15 @@ return true; if (auto *CI = dyn_cast(C)) { - if (CI->getBitWidth() > 64 || - (CI->getBitWidth() & 7) != 0) - return false; - - uint64_t Val = CI->getZExtValue(); + APInt Val = CI->getValue(); unsigned IntBytes = unsigned(CI->getBitWidth()/8); for (unsigned i = 0; i != BytesLeft && ByteOffset != IntBytes; ++i) { - int n = ByteOffset; + unsigned n = ByteOffset; if (!DL.isLittleEndian()) n = IntBytes - n - 1; - CurPtr[i] = (unsigned char)(Val >> (n * 8)); + if (n <= IntBytes) + CurPtr[i] = (unsigned char)(Val.lshr(n * 8).getZExtValue()); ++ByteOffset; } return true; Index: llvm/test/CodeGen/X86/load-local-v4i5.ll =================================================================== --- llvm/test/CodeGen/X86/load-local-v4i5.ll +++ llvm/test/CodeGen/X86/load-local-v4i5.ll @@ -6,27 +6,24 @@ define void @_start() { ; CHECK-LABEL: _start: ; CHECK: # %bb.0: # %Entry -; CHECK-NEXT: movl __unnamed_1(%rip), %eax -; CHECK-NEXT: movl %eax, -12(%rsp) -; CHECK-NEXT: movzbl -9(%rsp), %ecx +; CHECK-NEXT: movl $0, -12(%rsp) +; CHECK-NEXT: movzbl -9(%rsp), %eax +; CHECK-NEXT: movzbl -11(%rsp), %ecx ; CHECK-NEXT: movzbl -10(%rsp), %edx -; CHECK-NEXT: movzbl -11(%rsp), %esi -; CHECK-NEXT: movzbl %cl, %edi -; CHECK-NEXT: shrb %cl -; CHECK-NEXT: movb %cl, -2(%rsp) -; CHECK-NEXT: andl $31, %eax -; CHECK-NEXT: andl $31, %esi -; CHECK-NEXT: shll $5, %esi -; CHECK-NEXT: orl %eax, %esi +; CHECK-NEXT: movzbl %al, %esi +; CHECK-NEXT: shrb %al +; CHECK-NEXT: movb %al, -2(%rsp) ; CHECK-NEXT: andl $31, %edx ; CHECK-NEXT: shll $10, %edx -; CHECK-NEXT: orl %esi, %edx -; CHECK-NEXT: movl %edi, %eax +; CHECK-NEXT: andl $31, %ecx +; CHECK-NEXT: shll $5, %ecx +; CHECK-NEXT: orl %edx, %ecx +; CHECK-NEXT: movl %esi, %eax ; CHECK-NEXT: shll $15, %eax -; CHECK-NEXT: orl %edx, %eax +; CHECK-NEXT: orl %ecx, %eax ; CHECK-NEXT: movw %ax, -4(%rsp) -; CHECK-NEXT: movb %dil, -5(%rsp) -; CHECK-NEXT: cmpb $31, %dil +; CHECK-NEXT: movb %sil, -5(%rsp) +; CHECK-NEXT: cmpb $31, %sil ; CHECK-NEXT: je .LBB0_2 ; CHECK-NEXT: # %bb.1: # %Then ; CHECK-NEXT: int3 Index: llvm/test/Transforms/InstCombine/constant-fold.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/InstCombine/constant-fold.ll @@ -0,0 +1,23 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 +; RUN: opt < %s -passes=instcombine -S -data-layout="e" | FileCheck %s --check-prefixes=CHECK,LE +; RUN: opt < %s -passes=instcombine -S -data-layout="E" | FileCheck %s --check-prefixes=CHECK,BE +@global128 = internal constant i128 1125899906842625 +@global42 = internal constant i125 1125899906842625 +define i128 @load-128bit(){ +; CHECK-LABEL: define i128 @load-128bit() { +; CHECK-NEXT: ret i128 1125899906842625 +; + %1 = load i128, ptr @global128, align 4 + ret i128 %1 +} + +define i42 @load-42bit(){ +; LE-LABEL: define i42 @load-42bit() { +; LE-NEXT: ret i42 1 +; +; BE-LABEL: define i42 @load-42bit() { +; BE-NEXT: ret i42 0 +; + %1 = load i42, ptr @global42, align 4 + ret i42 %1 +} Index: llvm/test/Transforms/InstCombine/load-store-forward.ll =================================================================== --- llvm/test/Transforms/InstCombine/load-store-forward.ll +++ llvm/test/Transforms/InstCombine/load-store-forward.ll @@ -39,10 +39,13 @@ } define i17 @vec_store_load_first_odd_size(ptr %p) { -; CHECK-LABEL: @vec_store_load_first_odd_size( -; CHECK-NEXT: store <2 x i17> , ptr [[P:%.*]], align 8 -; CHECK-NEXT: [[LOAD:%.*]] = load i17, ptr [[P]], align 4 -; CHECK-NEXT: ret i17 [[LOAD]] +; LITTLE-LABEL: @vec_store_load_first_odd_size( +; LITTLE-NEXT: store <2 x i17> , ptr [[P:%.*]], align 8 +; LITTLE-NEXT: ret i17 1 +; +; BIG-LABEL: @vec_store_load_first_odd_size( +; BIG-NEXT: store <2 x i17> , ptr [[P:%.*]], align 8 +; BIG-NEXT: ret i17 256 ; store <2 x i17> , ptr %p %load = load i17, ptr %p