Index: llvm/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/lib/Analysis/ValueTracking.cpp +++ llvm/lib/Analysis/ValueTracking.cpp @@ -1610,6 +1610,10 @@ Known.One |= Known2.One.reverseBits(); break; case Intrinsic::bswap: + // APInt::byteSwap doesn't handle these cases + if (BitWidth < 16 || BitWidth % 16 != 0) + break; + computeKnownBits(I->getOperand(0), Known2, Depth + 1, Q); Known.Zero |= Known2.Zero.byteSwap(); Known.One |= Known2.One.byteSwap(); Index: llvm/test/Analysis/ValueTracking/bswap.ll =================================================================== --- /dev/null +++ llvm/test/Analysis/ValueTracking/bswap.ll @@ -0,0 +1,27 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -instsimplify -S < %s | FileCheck %s + +; Make sure there's no assert on weird sized bswaps + +declare i8 @llvm.bswap.i8(i8) #1 +declare i24 @llvm.bswap.i24(i24) #1 + +define i8 @bswap_i8(i8 %src) { +; CHECK-LABEL: @bswap_i8( +; CHECK-NEXT: [[BSWAP:%.*]] = call i8 @llvm.bswap.i8(i8 [[SRC:%.*]]) +; CHECK-NEXT: ret i8 [[BSWAP]] +; + %bswap = call i8 @llvm.bswap.i8(i8 %src) + ret i8 %bswap +} + +define i24 @bswap_i24(i24 %src) { +; CHECK-LABEL: @bswap_i24( +; CHECK-NEXT: [[BSWAP:%.*]] = call i24 @llvm.bswap.i24(i24 [[SRC:%.*]]) +; CHECK-NEXT: ret i24 [[BSWAP]] +; + %bswap = call i24 @llvm.bswap.i24(i24 %src) + ret i24 %bswap +} + +attributes #1 = { nounwind readnone speculatable willreturn }