Index: flang/lib/Lower/IntrinsicCall.cpp =================================================================== --- flang/lib/Lower/IntrinsicCall.cpp +++ flang/lib/Lower/IntrinsicCall.cpp @@ -441,6 +441,10 @@ getRuntimeCallGenerator(llvm::StringRef name, mlir::FunctionType soughtFuncType); + // Helper function that counts the number of set bits in the given value. + mlir::Value countOnes(mlir::Type resultType, mlir::Value x, + const std::vector &masks); + /// Lowering for the ABS intrinsic. The ABS intrinsic expects one argument in /// the llvm::ArrayRef. The ABS intrinsic is lowered into MLIR/FIR operation /// if the argument is an integer, into llvm intrinsics if the argument is @@ -520,6 +524,8 @@ mlir::Value genNot(mlir::Type, llvm::ArrayRef); fir::ExtendedValue genNull(mlir::Type, llvm::ArrayRef); fir::ExtendedValue genPack(mlir::Type, llvm::ArrayRef); + mlir::Value genPopcnt(mlir::Type, llvm::ArrayRef); + mlir::Value genPoppar(mlir::Type, llvm::ArrayRef); fir::ExtendedValue genPresent(mlir::Type, llvm::ArrayRef); fir::ExtendedValue genProduct(mlir::Type, llvm::ArrayRef); void genRandomInit(llvm::ArrayRef); @@ -845,6 +851,8 @@ {"mask", asBox}, {"vector", asBox, handleDynamicOptional}}}, /*isElemental=*/false}, + {"popcnt", &I::genPopcnt}, + {"poppar", &I::genPoppar}, {"present", &I::genPresent, {{{"a", asInquired}}}, @@ -3416,6 +3424,86 @@ "unexpected result for PACK"); } +mlir::Value IntrinsicLibrary::countOnes(mlir::Type resultType, mlir::Value x, + const std::vector &masks) { + mlir::Type iTy = x.getType(); + for (size_t i = 0; i < masks.size() - 1; i++) { + mlir::Value mask = builder.createIntegerConstant(loc, iTy, masks[i]); + mlir::Value len = builder.createIntegerConstant(loc, iTy, 1 << i); + + mlir::Value lhs = builder.create(loc, x, mask); + mlir::Value shift = builder.create(loc, x, len); + mlir::Value rhs = builder.create(loc, shift, mask); + x = builder.create(loc, lhs, rhs); + } + + mlir::Value mask = builder.createIntegerConstant(loc, iTy, masks.back()); + mlir::Value len = + builder.createIntegerConstant(loc, iTy, 1 << (masks.size() - 1)); + mlir::Value lhs = builder.create(loc, x, mask); + mlir::Value rhs = builder.create(loc, x, len); + mlir::Value ones = builder.create(loc, lhs, rhs); + + return builder.createConvert(loc, resultType, ones); +} + +// POPCNT +mlir::Value IntrinsicLibrary::genPopcnt(mlir::Type resultType, + llvm::ArrayRef args) { + assert(args.size() == 1); + + // What follows are the algorithms in flang/Common/bit-population-count.h + // implemented directly in FIR. See IntrinsicLibrary::countOnes for the + // actual implementation. + unsigned bits = args[0].getType().getIntOrFloatBitWidth(); + + if (bits <= 8) { + return countOnes(resultType, args[0], {0x55, 0x33, 0xf}); + } else if (bits <= 16) { + return countOnes(resultType, args[0], {0x5555, 0x3333, 0x0f0f, 0x1f}); + } else if (bits <= 32) { + return countOnes(resultType, args[0], + {0x55555555, 0x33333333, 0x0f0f0f0f, 0x001f001f, 0x3f}); + } else if (bits <= 64) { + return countOnes(resultType, args[0], + {0x5555555555555555, 0x3333333333333333, + 0x0f0f0f0f0f0f0f0f, 0x001f001f001f001f, + 0x0000003f0000003f, 0x7f}); + } else if (bits <= 128) { + // Split the 128-bit integer into two 64-bit integers and calculate the + // counts for each separately. + std::vector masks{0x5555555555555555, 0x3333333333333333, + 0x0f0f0f0f0f0f0f0f, 0x001f001f001f001f, + 0x0000003f0000003f, 0x7f}; + + mlir::Type i64Ty = builder.getIntegerType(64); + mlir::Value lo = builder.createConvert(loc, i64Ty, args[0]); + mlir::Value loCnt = countOnes(resultType, lo, masks); + + mlir::Type i128Ty = builder.getIntegerType(128); + mlir::Value c64 = builder.createIntegerConstant(loc, i128Ty, 64); + mlir::Value hiBits = + builder.create(loc, args[0], c64); + mlir::Value hi = builder.createConvert(loc, i64Ty, hiBits); + mlir::Value hiCnt = countOnes(resultType, hi, masks); + + return builder.create(loc, loCnt, hiCnt); + } else { + fir::emitFatalError(loc, "Unsupported kind for POPCNT"); + } +} + +// POPPAR +mlir::Value IntrinsicLibrary::genPoppar(mlir::Type resultType, + llvm::ArrayRef args) { + assert(args.size() == 1); + + mlir::Value count = genPopcnt(resultType, args); + mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); + + return builder.create(loc, count, one); +} + // PRESENT fir::ExtendedValue IntrinsicLibrary::genPresent(mlir::Type, Index: flang/test/Evaluate/fold-popcnt.f90 =================================================================== --- /dev/null +++ flang/test/Evaluate/fold-popcnt.f90 @@ -0,0 +1,88 @@ +! RUN: %python %S/test_folding.py %s %flang_fc1 +! Test counts of set bits. + +module popcnt_tests + logical, parameter :: test_z1 = popcnt(0_1) .EQ. 0 + logical, parameter :: test_o1 = popcnt(1_1) .EQ. 1 + logical, parameter :: test_t1 = popcnt(2_1) .EQ. 1 + logical, parameter :: test_f1 = popcnt(15_1) .EQ. 4 + logical, parameter :: test_b1 = popcnt(16_1) .EQ. 1 + logical, parameter :: test_m11 = popcnt(-1_1) .EQ. 8 + logical, parameter :: test_m12 = popcnt(-2_1) .EQ. 7 + logical, parameter :: test_mb1 = popcnt(-120_1) .EQ. 2 + + logical, parameter :: test_z2 = popcnt(0_2) .EQ. 0 + logical, parameter :: test_o2 = popcnt(1_2) .EQ. 1 + logical, parameter :: test_t2 = popcnt(2_2) .EQ. 1 + logical, parameter :: test_f2 = popcnt(15_2) .EQ. 4 + logical, parameter :: test_m21 = popcnt(-1_2) .EQ. 16 + logical, parameter :: test_m22 = popcnt(-2_2) .EQ. 15 + logical, parameter :: test_mb2 = popcnt(-32640_2) .EQ. 2 + + logical, parameter :: test_z4 = popcnt(0_4) .EQ. 0 + logical, parameter :: test_o4 = popcnt(1_4) .EQ. 1 + logical, parameter :: test_t4 = popcnt(2_4) .EQ. 1 + logical, parameter :: test_f4 = popcnt(15_4) .EQ. 4 + logical, parameter :: test_m41 = popcnt(-1_4) .EQ. 32 + logical, parameter :: test_m42 = popcnt(-2_4) .EQ. 31 + logical, parameter :: test_mb4 = popcnt(-2147450880_4) .EQ. 2 + + logical, parameter :: test_z8 = popcnt(0_8) .EQ. 0 + logical, parameter :: test_o8 = popcnt(1_8) .EQ. 1 + logical, parameter :: test_t8 = popcnt(2_8) .EQ. 1 + logical, parameter :: test_f8 = popcnt(15_8) .EQ. 4 + logical, parameter :: test_m81 = popcnt(-1_8) .EQ. 64 + logical, parameter :: test_m82 = popcnt(-2_8) .EQ. 63 + logical, parameter :: test_mb8 = popcnt(-9223372034707292160_8) .EQ. 2 + + logical, parameter :: test_z16 = popcnt(0_16) .EQ. 0 + logical, parameter :: test_o16 = popcnt(1_16) .EQ. 1 + logical, parameter :: test_t16 = popcnt(2_16) .EQ. 1 + logical, parameter :: test_f16 = popcnt(15_16) .EQ. 4 + logical, parameter :: test_m161 = popcnt(-1_16) .EQ. 128 + logical, parameter :: test_m162 = popcnt(-2_16) .EQ. 127 + logical, parameter :: test_mb16 = popcnt(18446744073709551616_16) .EQ. 1 +end module popcnt_tests + +module poppar_tests + logical, parameter :: test_z1 = poppar(0_1) .EQ. 0 + logical, parameter :: test_o1 = poppar(1_1) .EQ. 1 + logical, parameter :: test_t1 = poppar(2_1) .EQ. 1 + logical, parameter :: test_f1 = poppar(15_1) .EQ. 0 + logical, parameter :: test_b1 = poppar(16_1) .EQ. 1 + logical, parameter :: test_m11 = poppar(-1_1) .EQ. 0 + logical, parameter :: test_m12 = poppar(-2_1) .EQ. 1 + logical, parameter :: test_mb1 = poppar(-120_1) .EQ. 0 + + logical, parameter :: test_z2 = poppar(0_2) .EQ. 0 + logical, parameter :: test_o2 = poppar(1_2) .EQ. 1 + logical, parameter :: test_t2 = poppar(2_2) .EQ. 1 + logical, parameter :: test_f2 = poppar(15_2) .EQ. 0 + logical, parameter :: test_m21 = poppar(-1_2) .EQ. 0 + logical, parameter :: test_m22 = poppar(-2_2) .EQ. 1 + logical, parameter :: test_mb2 = poppar(-32640_2) .EQ. 0 + + logical, parameter :: test_z4 = poppar(0_4) .EQ. 0 + logical, parameter :: test_o4 = poppar(1_4) .EQ. 1 + logical, parameter :: test_t4 = poppar(2_4) .EQ. 1 + logical, parameter :: test_f4 = poppar(15_4) .EQ. 0 + logical, parameter :: test_m41 = poppar(-1_4) .EQ. 0 + logical, parameter :: test_m42 = poppar(-2_4) .EQ. 1 + logical, parameter :: test_mb4 = poppar(-2147450880_4) .EQ. 0 + + logical, parameter :: test_z8 = poppar(0_8) .EQ. 0 + logical, parameter :: test_o8 = poppar(1_8) .EQ. 1 + logical, parameter :: test_t8 = poppar(2_8) .EQ. 1 + logical, parameter :: test_f8 = poppar(15_8) .EQ. 0 + logical, parameter :: test_m81 = poppar(-1_8) .EQ. 0 + logical, parameter :: test_m82 = poppar(-2_8) .EQ. 1 + logical, parameter :: test_mb8 = poppar(-9223372034707292160_8) .EQ. 0 + + logical, parameter :: test_z16 = poppar(0_16) .EQ. 0 + logical, parameter :: test_o16 = poppar(1_16) .EQ. 1 + logical, parameter :: test_t16 = poppar(2_16) .EQ. 1 + logical, parameter :: test_f16 = poppar(15_16) .EQ. 0 + logical, parameter :: test_m161 = poppar(-1_16) .EQ. 0 + logical, parameter :: test_m162 = poppar(-2_16) .EQ. 1 + logical, parameter :: test_mb16 = poppar(18446744073709551616_16) .EQ. 1 +end module poppar_tests Index: flang/test/Lower/Intrinsics/popcnt.f90 =================================================================== --- /dev/null +++ flang/test/Lower/Intrinsics/popcnt.f90 @@ -0,0 +1,240 @@ +! RUN: bbc -emit-fir %s -o - | FileCheck %s + +! CHECK-LABEL: popcnt1_test +! CHECK-SAME: %[[AREF:.*]]: !fir.ref{{.*}}, %[[BREF:.*]]: !fir.ref{{.*}} +subroutine popcnt1_test(a, b) + integer(1) :: a + integer :: b + + ! CHECK: %[[X0:.*]] = fir.load %[[AREF]] : !fir.ref + b = popcnt(a) + ! CHECK: %[[CM0:.*]] = arith.constant 85 : i8 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i8 + ! CHECK: %[[L0:.*]] = arith.andi %[[X0]], %[[CM0]] : i8 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[X0]], %[[CS0]] : i8 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i8 + ! CHECK: %[[X1:.*]] = arith.addi %[[L0]], %[[R0]] : i8 + ! CHECK: %[[CM1:.*]] = arith.constant 51 : i8 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i8 + ! CHECK: %[[L1:.*]] = arith.andi %[[X1]], %[[CM1]] : i8 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[X1]], %[[CS1]] : i8 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i8 + ! CHECK: %[[X2:.*]] = arith.addi %[[L1]], %[[R1]] : i8 + ! CHECK: %[[CM2:.*]] = arith.constant 15 : i8 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i8 + ! CHECK: %[[L2:.*]] = arith.andi %[[X2]], %[[CM2]] : i8 + ! CHECK: %[[R2:.*]] = arith.shrui %[[X2]], %[[CS2]] : i8 + ! CHECK: %[[X3:.*]] = arith.addi %[[L2]], %[[R2]] : i8 + ! CHECK: %[[CONV:.*]] = fir.convert %[[X3]] : (i8) -> i32 + ! CHECK: fir.store %[[CONV]] to %[[BREF]] : !fir.ref +end subroutine popcnt1_test + +! CHECK-LABEL: popcnt2_test +! CHECK-SAME: %[[AREF:.*]]: !fir.ref{{.*}}, %[[BREF:.*]]: !fir.ref{{.*}} +subroutine popcnt2_test(a, b) + integer(2) :: a + integer :: b + + ! CHECK: %[[X0:.*]] = fir.load %[[AREF]] : !fir.ref + b = popcnt(a) + ! CHECK: %[[CM0:.*]] = arith.constant 21845 : i16 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i16 + ! CHECK: %[[L0:.*]] = arith.andi %[[X0]], %[[CM0]] : i16 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[X0]], %[[CS0]] : i16 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i16 + ! CHECK: %[[X1:.*]] = arith.addi %[[L0]], %[[R0]] : i16 + ! CHECK: %[[CM1:.*]] = arith.constant 13107 : i16 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i16 + ! CHECK: %[[L1:.*]] = arith.andi %[[X1]], %[[CM1]] : i16 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[X1]], %[[CS1]] : i16 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i16 + ! CHECK: %[[X2:.*]] = arith.addi %[[L1]], %[[R1]] : i16 + ! CHECK: %[[CM2:.*]] = arith.constant 3855 : i16 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i16 + ! CHECK: %[[L2:.*]] = arith.andi %[[X2]], %[[CM2]] : i16 + ! CHECK: %[[SHR2:.*]] = arith.shrui %[[X2]], %[[CS2]] : i16 + ! CHECK: %[[R2:.*]] = arith.andi %[[SHR2]], %[[CM2]] : i16 + ! CHECK: %[[X3:.*]] = arith.addi %[[L2]], %[[R2]] : i16 + ! CHECK: %[[CM3:.*]] = arith.constant 31 : i16 + ! CHECK: %[[CS3:.*]] = arith.constant 8 : i16 + ! CHECK: %[[L3:.*]] = arith.andi %[[X3]], %[[CM3]] : i16 + ! CHECK: %[[R3:.*]] = arith.shrui %[[X3]], %[[CS3]] : i16 + ! CHECK: %[[X4:.*]] = arith.addi %[[L3]], %[[R3]] : i16 + ! CHECK: %[[CONV:.*]] = fir.convert %[[X4]] : (i16) -> i32 + ! CHECK: fir.store %[[CONV]] to %[[BREF]] : !fir.ref +end subroutine popcnt2_test + +! CHECK-LABEL: popcnt4_test +! CHECK-SAME: %[[AREF:.*]]: !fir.ref{{.*}}, %[[BREF:.*]]: !fir.ref{{.*}} +subroutine popcnt4_test(a, b) + integer(4) :: a + integer :: b + + ! CHECK: %[[X0:.*]] = fir.load %[[AREF]] : !fir.ref + b = popcnt(a) + ! CHECK: %[[CM0:.*]] = arith.constant 1431655765 : i32 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i32 + ! CHECK: %[[L0:.*]] = arith.andi %[[X0]], %[[CM0]] : i32 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[X0]], %[[CS0]] : i32 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i32 + ! CHECK: %[[X1:.*]] = arith.addi %[[L0]], %[[R0]] : i32 + ! CHECK: %[[CM1:.*]] = arith.constant 858993459 : i32 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i32 + ! CHECK: %[[L1:.*]] = arith.andi %[[X1]], %[[CM1]] : i32 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[X1]], %[[CS1]] : i32 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i32 + ! CHECK: %[[X2:.*]] = arith.addi %[[L1]], %[[R1]] : i32 + ! CHECK: %[[CM2:.*]] = arith.constant 252645135 : i32 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i32 + ! CHECK: %[[L2:.*]] = arith.andi %[[X2]], %[[CM2]] : i32 + ! CHECK: %[[SHR2:.*]] = arith.shrui %[[X2]], %[[CS2]] : i32 + ! CHECK: %[[R2:.*]] = arith.andi %[[SHR2]], %[[CM2]] : i32 + ! CHECK: %[[X3:.*]] = arith.addi %[[L2]], %[[R2]] : i32 + ! CHECK: %[[CM3:.*]] = arith.constant 2031647 : i32 + ! CHECK: %[[CS3:.*]] = arith.constant 8 : i32 + ! CHECK: %[[L3:.*]] = arith.andi %[[X3]], %[[CM3]] : i32 + ! CHECK: %[[SHR3:.*]] = arith.shrui %[[X3]], %[[CS3]] : i32 + ! CHECK: %[[R3:.*]] = arith.andi %[[SHR3]], %[[CM3]] : i32 + ! CHECK: %[[X4:.*]] = arith.addi %[[L3]], %[[R3]] : i32 + ! CHECK: %[[CM4:.*]] = arith.constant 63 : i32 + ! CHECK: %[[CS4:.*]] = arith.constant 16 : i32 + ! CHECK: %[[L4:.*]] = arith.andi %[[X4]], %[[CM4]] : i32 + ! CHECK: %[[R4:.*]] = arith.shrui %[[X4]], %[[CS4]] : i32 + ! CHECK: %[[X5:.*]] = arith.addi %[[L4]], %[[R4]] : i32 + ! CHECK: fir.store %[[X5]] to %[[BREF]] : !fir.ref +end subroutine popcnt4_test + +! CHECK-LABEL: popcnt8_test +! CHECK-SAME: %[[AREF:.*]]: !fir.ref{{.*}}, %[[BREF:.*]]: !fir.ref{{.*}} +subroutine popcnt8_test(a, b) + integer(8) :: a + integer :: b + + ! CHECK: %[[X0:.*]] = fir.load %[[AREF]] : !fir.ref + b = popcnt(a) + ! CHECK: %[[CM0:.*]] = arith.constant 6148914691236517205 : i64 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i64 + ! CHECK: %[[L0:.*]] = arith.andi %[[X0]], %[[CM0]] : i64 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[X0]], %[[CS0]] : i64 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i64 + ! CHECK: %[[X1:.*]] = arith.addi %[[L0]], %[[R0]] : i64 + ! CHECK: %[[CM1:.*]] = arith.constant 3689348814741910323 : i64 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i64 + ! CHECK: %[[L1:.*]] = arith.andi %[[X1]], %[[CM1]] : i64 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[X1]], %[[CS1]] : i64 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i64 + ! CHECK: %[[X2:.*]] = arith.addi %[[L1]], %[[R1]] : i64 + ! CHECK: %[[CM2:.*]] = arith.constant 1085102592571150095 : i64 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i64 + ! CHECK: %[[L2:.*]] = arith.andi %[[X2]], %[[CM2]] : i64 + ! CHECK: %[[SHR2:.*]] = arith.shrui %[[X2]], %[[CS2]] : i64 + ! CHECK: %[[R2:.*]] = arith.andi %[[SHR2]], %[[CM2]] : i64 + ! CHECK: %[[X3:.*]] = arith.addi %[[L2]], %[[R2]] : i64 + ! CHECK: %[[CM3:.*]] = arith.constant 8725857424048159 : i64 + ! CHECK: %[[CS3:.*]] = arith.constant 8 : i64 + ! CHECK: %[[L3:.*]] = arith.andi %[[X3]], %[[CM3]] : i64 + ! CHECK: %[[SHR3:.*]] = arith.shrui %[[X3]], %[[CS3]] : i64 + ! CHECK: %[[R3:.*]] = arith.andi %[[SHR3]], %[[CM3]] : i64 + ! CHECK: %[[X4:.*]] = arith.addi %[[L3]], %[[R3]] : i64 + ! CHECK: %[[CM4:.*]] = arith.constant 270582939711 : i64 + ! CHECK: %[[CS4:.*]] = arith.constant 16 : i64 + ! CHECK: %[[L4:.*]] = arith.andi %[[X4]], %[[CM4]] : i64 + ! CHECK: %[[SHR4:.*]] = arith.shrui %[[X4]], %[[CS4]] : i64 + ! CHECK: %[[R4:.*]] = arith.andi %[[SHR4]], %[[CM4]] : i64 + ! CHECK: %[[X5:.*]] = arith.addi %[[L4]], %[[R4]] : i64 + ! CHECK: %[[CM5:.*]] = arith.constant 127 : i64 + ! CHECK: %[[CS5:.*]] = arith.constant 32 : i64 + ! CHECK: %[[L5:.*]] = arith.andi %[[X5]], %[[CM5]] : i64 + ! CHECK: %[[R5:.*]] = arith.shrui %[[X5]], %[[CS5]] : i64 + ! CHECK: %[[X6:.*]] = arith.addi %[[L5]], %[[R5]] : i64 + ! CHECK: %[[CONV:.*]] = fir.convert %[[X6]] : (i64) -> i32 + ! CHECK: fir.store %[[CONV]] to %[[BREF]] : !fir.ref +end subroutine popcnt8_test + +! CHECK-LABEL: popcnt16_test +! CHECK-SAME: %[[AREF:.*]]: !fir.ref{{.*}}, %[[BREF:.*]]: !fir.ref{{.*}} +subroutine popcnt16_test(a, b) + integer(16) :: a + integer :: b + + ! CHECK: %[[XVAL:.*]] = fir.load %[[AREF]] : !fir.ref + b = popcnt(a) + ! CHECK: %[[X0:.*]] = fir.convert %[[XVAL]] : (i128) -> i64 + ! CHECK: %[[CM0:.*]] = arith.constant 6148914691236517205 : i64 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i64 + ! CHECK: %[[L0:.*]] = arith.andi %[[X0]], %[[CM0]] : i64 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[X0]], %[[CS0]] : i64 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i64 + ! CHECK: %[[X1:.*]] = arith.addi %[[L0]], %[[R0]] : i64 + ! CHECK: %[[CM1:.*]] = arith.constant 3689348814741910323 : i64 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i64 + ! CHECK: %[[L1:.*]] = arith.andi %[[X1]], %[[CM1]] : i64 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[X1]], %[[CS1]] : i64 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i64 + ! CHECK: %[[X2:.*]] = arith.addi %[[L1]], %[[R1]] : i64 + ! CHECK: %[[CM2:.*]] = arith.constant 1085102592571150095 : i64 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i64 + ! CHECK: %[[L2:.*]] = arith.andi %[[X2]], %[[CM2]] : i64 + ! CHECK: %[[SHR2:.*]] = arith.shrui %[[X2]], %[[CS2]] : i64 + ! CHECK: %[[R2:.*]] = arith.andi %[[SHR2]], %[[CM2]] : i64 + ! CHECK: %[[X3:.*]] = arith.addi %[[L2]], %[[R2]] : i64 + ! CHECK: %[[CM3:.*]] = arith.constant 8725857424048159 : i64 + ! CHECK: %[[CS3:.*]] = arith.constant 8 : i64 + ! CHECK: %[[L3:.*]] = arith.andi %[[X3]], %[[CM3]] : i64 + ! CHECK: %[[SHR3:.*]] = arith.shrui %[[X3]], %[[CS3]] : i64 + ! CHECK: %[[R3:.*]] = arith.andi %[[SHR3]], %[[CM3]] : i64 + ! CHECK: %[[X4:.*]] = arith.addi %[[L3]], %[[R3]] : i64 + ! CHECK: %[[CM4:.*]] = arith.constant 270582939711 : i64 + ! CHECK: %[[CS4:.*]] = arith.constant 16 : i64 + ! CHECK: %[[L4:.*]] = arith.andi %[[X4]], %[[CM4]] : i64 + ! CHECK: %[[SHR4:.*]] = arith.shrui %[[X4]], %[[CS4]] : i64 + ! CHECK: %[[R4:.*]] = arith.andi %[[SHR4]], %[[CM4]] : i64 + ! CHECK: %[[X5:.*]] = arith.addi %[[L4]], %[[R4]] : i64 + ! CHECK: %[[CM5:.*]] = arith.constant 127 : i64 + ! CHECK: %[[CS5:.*]] = arith.constant 32 : i64 + ! CHECK: %[[L5:.*]] = arith.andi %[[X5]], %[[CM5]] : i64 + ! CHECK: %[[R5:.*]] = arith.shrui %[[X5]], %[[CS5]] : i64 + ! CHECK: %[[X6:.*]] = arith.addi %[[L5]], %[[R5]] : i64 + ! CHECK: %[[LO:.*]] = fir.convert %[[X6]] : (i64) -> i32 + ! CHECK: %[[C64:.*]] = arith.constant 64 : i128 + ! CHECK: %[[YSH:.*]] = arith.shrui %[[XVAL]], %[[C64]] : i128 + ! CHECK: %[[Y0:.*]] = fir.convert %[[YSH]] : (i128) -> i64 + ! CHECK: %[[CM0:.*]] = arith.constant 6148914691236517205 : i64 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i64 + ! CHECK: %[[L0:.*]] = arith.andi %[[Y0]], %[[CM0]] : i64 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[Y0]], %[[CS0]] : i64 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i64 + ! CHECK: %[[Y1:.*]] = arith.addi %[[L0]], %[[R0]] : i64 + ! CHECK: %[[CM1:.*]] = arith.constant 3689348814741910323 : i64 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i64 + ! CHECK: %[[L1:.*]] = arith.andi %[[Y1]], %[[CM1]] : i64 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[Y1]], %[[CS1]] : i64 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i64 + ! CHECK: %[[Y2:.*]] = arith.addi %[[L1]], %[[R1]] : i64 + ! CHECK: %[[CM2:.*]] = arith.constant 1085102592571150095 : i64 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i64 + ! CHECK: %[[L2:.*]] = arith.andi %[[Y2]], %[[CM2]] : i64 + ! CHECK: %[[SHR2:.*]] = arith.shrui %[[Y2]], %[[CS2]] : i64 + ! CHECK: %[[R2:.*]] = arith.andi %[[SHR2]], %[[CM2]] : i64 + ! CHECK: %[[Y3:.*]] = arith.addi %[[L2]], %[[R2]] : i64 + ! CHECK: %[[CM3:.*]] = arith.constant 8725857424048159 : i64 + ! CHECK: %[[CS3:.*]] = arith.constant 8 : i64 + ! CHECK: %[[L3:.*]] = arith.andi %[[Y3]], %[[CM3]] : i64 + ! CHECK: %[[SHR3:.*]] = arith.shrui %[[Y3]], %[[CS3]] : i64 + ! CHECK: %[[R3:.*]] = arith.andi %[[SHR3]], %[[CM3]] : i64 + ! CHECK: %[[Y4:.*]] = arith.addi %[[L3]], %[[R3]] : i64 + ! CHECK: %[[CM4:.*]] = arith.constant 270582939711 : i64 + ! CHECK: %[[CS4:.*]] = arith.constant 16 : i64 + ! CHECK: %[[L4:.*]] = arith.andi %[[Y4]], %[[CM4]] : i64 + ! CHECK: %[[SHR4:.*]] = arith.shrui %[[Y4]], %[[CS4]] : i64 + ! CHECK: %[[R4:.*]] = arith.andi %[[SHR4]], %[[CM4]] : i64 + ! CHECK: %[[Y5:.*]] = arith.addi %[[L4]], %[[R4]] : i64 + ! CHECK: %[[CM5:.*]] = arith.constant 127 : i64 + ! CHECK: %[[CS5:.*]] = arith.constant 32 : i64 + ! CHECK: %[[L5:.*]] = arith.andi %[[Y5]], %[[CM5]] : i64 + ! CHECK: %[[R5:.*]] = arith.shrui %[[Y5]], %[[CS5]] : i64 + ! CHECK: %[[Y6:.*]] = arith.addi %[[L5]], %[[R5]] : i64 + ! CHECK: %[[HI:.*]] = fir.convert %[[Y6]] : (i64) -> i32 + ! CHECK: %[[CNT:.*]] = arith.addi %[[LO]], %[[HI]] : i32 + ! CHECK: fir.store %[[CNT]] to %[[BREF]] : !fir.ref +end subroutine popcnt16_test Index: flang/test/Lower/Intrinsics/poppar.f90 =================================================================== --- /dev/null +++ flang/test/Lower/Intrinsics/poppar.f90 @@ -0,0 +1,250 @@ +! RUN: bbc -emit-fir %s -o - | FileCheck %s + +! CHECK-LABEL: poppar1_test +! CHECK-SAME: %[[AREF:.*]]: !fir.ref{{.*}}, %[[BREF:.*]]: !fir.ref{{.*}} +subroutine poppar1_test(a, b) + integer(1) :: a + integer :: b + + ! CHECK: %[[X0:.*]] = fir.load %[[AREF]] : !fir.ref + b = poppar(a) + ! CHECK: %[[CM0:.*]] = arith.constant 85 : i8 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i8 + ! CHECK: %[[L0:.*]] = arith.andi %[[X0]], %[[CM0]] : i8 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[X0]], %[[CS0]] : i8 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i8 + ! CHECK: %[[X1:.*]] = arith.addi %[[L0]], %[[R0]] : i8 + ! CHECK: %[[CM1:.*]] = arith.constant 51 : i8 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i8 + ! CHECK: %[[L1:.*]] = arith.andi %[[X1]], %[[CM1]] : i8 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[X1]], %[[CS1]] : i8 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i8 + ! CHECK: %[[X2:.*]] = arith.addi %[[L1]], %[[R1]] : i8 + ! CHECK: %[[CM2:.*]] = arith.constant 15 : i8 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i8 + ! CHECK: %[[L2:.*]] = arith.andi %[[X2]], %[[CM2]] : i8 + ! CHECK: %[[R2:.*]] = arith.shrui %[[X2]], %[[CS2]] : i8 + ! CHECK: %[[X3:.*]] = arith.addi %[[L2]], %[[R2]] : i8 + ! CHECK: %[[CONV:.*]] = fir.convert %[[X3]] : (i8) -> i32 + ! CHECK: %[[CONE:.*]] = arith.constant 1 : i32 + ! CHECK: %[[RSLT:.*]] = arith.andi %[[CONV]], %[[CONE]] : i32 + ! CHECK: fir.store %[[RSLT]] to %[[BREF]] : !fir.ref +end subroutine poppar1_test + +! CHECK-LABEL: poppar2_test +! CHECK-SAME: %[[AREF:.*]]: !fir.ref{{.*}}, %[[BREF:.*]]: !fir.ref{{.*}} +subroutine poppar2_test(a, b) + integer(2) :: a + integer :: b + + ! CHECK: %[[X0:.*]] = fir.load %[[AREF]] : !fir.ref + b = poppar(a) + ! CHECK: %[[CM0:.*]] = arith.constant 21845 : i16 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i16 + ! CHECK: %[[L0:.*]] = arith.andi %[[X0]], %[[CM0]] : i16 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[X0]], %[[CS0]] : i16 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i16 + ! CHECK: %[[X1:.*]] = arith.addi %[[L0]], %[[R0]] : i16 + ! CHECK: %[[CM1:.*]] = arith.constant 13107 : i16 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i16 + ! CHECK: %[[L1:.*]] = arith.andi %[[X1]], %[[CM1]] : i16 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[X1]], %[[CS1]] : i16 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i16 + ! CHECK: %[[X2:.*]] = arith.addi %[[L1]], %[[R1]] : i16 + ! CHECK: %[[CM2:.*]] = arith.constant 3855 : i16 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i16 + ! CHECK: %[[L2:.*]] = arith.andi %[[X2]], %[[CM2]] : i16 + ! CHECK: %[[SHR2:.*]] = arith.shrui %[[X2]], %[[CS2]] : i16 + ! CHECK: %[[R2:.*]] = arith.andi %[[SHR2]], %[[CM2]] : i16 + ! CHECK: %[[X3:.*]] = arith.addi %[[L2]], %[[R2]] : i16 + ! CHECK: %[[CM3:.*]] = arith.constant 31 : i16 + ! CHECK: %[[CS3:.*]] = arith.constant 8 : i16 + ! CHECK: %[[L3:.*]] = arith.andi %[[X3]], %[[CM3]] : i16 + ! CHECK: %[[R3:.*]] = arith.shrui %[[X3]], %[[CS3]] : i16 + ! CHECK: %[[X4:.*]] = arith.addi %[[L3]], %[[R3]] : i16 + ! CHECK: %[[CONV:.*]] = fir.convert %[[X4]] : (i16) -> i32 + ! CHECK: %[[CONE:.*]] = arith.constant 1 : i32 + ! CHECK: %[[RSLT:.*]] = arith.andi %[[CONV]], %[[CONE]] : i32 + ! CHECK: fir.store %[[RSLT]] to %[[BREF]] : !fir.ref +end subroutine poppar2_test + +! CHECK-LABEL: poppar4_test +! CHECK-SAME: %[[AREF:.*]]: !fir.ref{{.*}}, %[[BREF:.*]]: !fir.ref{{.*}} +subroutine poppar4_test(a, b) + integer(4) :: a + integer :: b + + ! CHECK: %[[X0:.*]] = fir.load %[[AREF]] : !fir.ref + b = poppar(a) + ! CHECK: %[[CM0:.*]] = arith.constant 1431655765 : i32 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i32 + ! CHECK: %[[L0:.*]] = arith.andi %[[X0]], %[[CM0]] : i32 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[X0]], %[[CS0]] : i32 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i32 + ! CHECK: %[[X1:.*]] = arith.addi %[[L0]], %[[R0]] : i32 + ! CHECK: %[[CM1:.*]] = arith.constant 858993459 : i32 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i32 + ! CHECK: %[[L1:.*]] = arith.andi %[[X1]], %[[CM1]] : i32 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[X1]], %[[CS1]] : i32 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i32 + ! CHECK: %[[X2:.*]] = arith.addi %[[L1]], %[[R1]] : i32 + ! CHECK: %[[CM2:.*]] = arith.constant 252645135 : i32 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i32 + ! CHECK: %[[L2:.*]] = arith.andi %[[X2]], %[[CM2]] : i32 + ! CHECK: %[[SHR2:.*]] = arith.shrui %[[X2]], %[[CS2]] : i32 + ! CHECK: %[[R2:.*]] = arith.andi %[[SHR2]], %[[CM2]] : i32 + ! CHECK: %[[X3:.*]] = arith.addi %[[L2]], %[[R2]] : i32 + ! CHECK: %[[CM3:.*]] = arith.constant 2031647 : i32 + ! CHECK: %[[CS3:.*]] = arith.constant 8 : i32 + ! CHECK: %[[L3:.*]] = arith.andi %[[X3]], %[[CM3]] : i32 + ! CHECK: %[[SHR3:.*]] = arith.shrui %[[X3]], %[[CS3]] : i32 + ! CHECK: %[[R3:.*]] = arith.andi %[[SHR3]], %[[CM3]] : i32 + ! CHECK: %[[X4:.*]] = arith.addi %[[L3]], %[[R3]] : i32 + ! CHECK: %[[CM4:.*]] = arith.constant 63 : i32 + ! CHECK: %[[CS4:.*]] = arith.constant 16 : i32 + ! CHECK: %[[L4:.*]] = arith.andi %[[X4]], %[[CM4]] : i32 + ! CHECK: %[[R4:.*]] = arith.shrui %[[X4]], %[[CS4]] : i32 + ! CHECK: %[[X5:.*]] = arith.addi %[[L4]], %[[R4]] : i32 + ! CHECK: %[[CONE:.*]] = arith.constant 1 : i32 + ! CHECK: %[[RSLT:.*]] = arith.andi %[[X5]], %[[CONE]] : i32 + ! CHECK: fir.store %[[RSLT]] to %[[BREF]] : !fir.ref +end subroutine poppar4_test + +! CHECK-LABEL: poppar8_test +! CHECK-SAME: %[[AREF:.*]]: !fir.ref{{.*}}, %[[BREF:.*]]: !fir.ref{{.*}} +subroutine poppar8_test(a, b) + integer(8) :: a + integer :: b + + ! CHECK: %[[X0:.*]] = fir.load %[[AREF]] : !fir.ref + b = poppar(a) + ! CHECK: %[[CM0:.*]] = arith.constant 6148914691236517205 : i64 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i64 + ! CHECK: %[[L0:.*]] = arith.andi %[[X0]], %[[CM0]] : i64 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[X0]], %[[CS0]] : i64 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i64 + ! CHECK: %[[X1:.*]] = arith.addi %[[L0]], %[[R0]] : i64 + ! CHECK: %[[CM1:.*]] = arith.constant 3689348814741910323 : i64 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i64 + ! CHECK: %[[L1:.*]] = arith.andi %[[X1]], %[[CM1]] : i64 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[X1]], %[[CS1]] : i64 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i64 + ! CHECK: %[[X2:.*]] = arith.addi %[[L1]], %[[R1]] : i64 + ! CHECK: %[[CM2:.*]] = arith.constant 1085102592571150095 : i64 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i64 + ! CHECK: %[[L2:.*]] = arith.andi %[[X2]], %[[CM2]] : i64 + ! CHECK: %[[SHR2:.*]] = arith.shrui %[[X2]], %[[CS2]] : i64 + ! CHECK: %[[R2:.*]] = arith.andi %[[SHR2]], %[[CM2]] : i64 + ! CHECK: %[[X3:.*]] = arith.addi %[[L2]], %[[R2]] : i64 + ! CHECK: %[[CM3:.*]] = arith.constant 8725857424048159 : i64 + ! CHECK: %[[CS3:.*]] = arith.constant 8 : i64 + ! CHECK: %[[L3:.*]] = arith.andi %[[X3]], %[[CM3]] : i64 + ! CHECK: %[[SHR3:.*]] = arith.shrui %[[X3]], %[[CS3]] : i64 + ! CHECK: %[[R3:.*]] = arith.andi %[[SHR3]], %[[CM3]] : i64 + ! CHECK: %[[X4:.*]] = arith.addi %[[L3]], %[[R3]] : i64 + ! CHECK: %[[CM4:.*]] = arith.constant 270582939711 : i64 + ! CHECK: %[[CS4:.*]] = arith.constant 16 : i64 + ! CHECK: %[[L4:.*]] = arith.andi %[[X4]], %[[CM4]] : i64 + ! CHECK: %[[SHR4:.*]] = arith.shrui %[[X4]], %[[CS4]] : i64 + ! CHECK: %[[R4:.*]] = arith.andi %[[SHR4]], %[[CM4]] : i64 + ! CHECK: %[[X5:.*]] = arith.addi %[[L4]], %[[R4]] : i64 + ! CHECK: %[[CM5:.*]] = arith.constant 127 : i64 + ! CHECK: %[[CS5:.*]] = arith.constant 32 : i64 + ! CHECK: %[[L5:.*]] = arith.andi %[[X5]], %[[CM5]] : i64 + ! CHECK: %[[R5:.*]] = arith.shrui %[[X5]], %[[CS5]] : i64 + ! CHECK: %[[X6:.*]] = arith.addi %[[L5]], %[[R5]] : i64 + ! CHECK: %[[CONV:.*]] = fir.convert %[[X6]] : (i64) -> i32 + ! CHECK: %[[CONE:.*]] = arith.constant 1 : i32 + ! CHECK: %[[RSLT:.*]] = arith.andi %[[CONV]], %[[CONE]] : i32 + ! CHECK: fir.store %[[RSLT]] to %[[BREF]] : !fir.ref +end subroutine poppar8_test + +! CHECK-LABEL: poppar16_test +! CHECK-SAME: %[[AREF:.*]]: !fir.ref{{.*}}, %[[BREF:.*]]: !fir.ref{{.*}} +subroutine poppar16_test(a, b) + integer(16) :: a + integer :: b + + ! CHECK: %[[XVAL:.*]] = fir.load %[[AREF]] : !fir.ref + b = poppar(a) + ! CHECK: %[[X0:.*]] = fir.convert %[[XVAL]] : (i128) -> i64 + ! CHECK: %[[CM0:.*]] = arith.constant 6148914691236517205 : i64 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i64 + ! CHECK: %[[L0:.*]] = arith.andi %[[X0]], %[[CM0]] : i64 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[X0]], %[[CS0]] : i64 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i64 + ! CHECK: %[[X1:.*]] = arith.addi %[[L0]], %[[R0]] : i64 + ! CHECK: %[[CM1:.*]] = arith.constant 3689348814741910323 : i64 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i64 + ! CHECK: %[[L1:.*]] = arith.andi %[[X1]], %[[CM1]] : i64 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[X1]], %[[CS1]] : i64 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i64 + ! CHECK: %[[X2:.*]] = arith.addi %[[L1]], %[[R1]] : i64 + ! CHECK: %[[CM2:.*]] = arith.constant 1085102592571150095 : i64 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i64 + ! CHECK: %[[L2:.*]] = arith.andi %[[X2]], %[[CM2]] : i64 + ! CHECK: %[[SHR2:.*]] = arith.shrui %[[X2]], %[[CS2]] : i64 + ! CHECK: %[[R2:.*]] = arith.andi %[[SHR2]], %[[CM2]] : i64 + ! CHECK: %[[X3:.*]] = arith.addi %[[L2]], %[[R2]] : i64 + ! CHECK: %[[CM3:.*]] = arith.constant 8725857424048159 : i64 + ! CHECK: %[[CS3:.*]] = arith.constant 8 : i64 + ! CHECK: %[[L3:.*]] = arith.andi %[[X3]], %[[CM3]] : i64 + ! CHECK: %[[SHR3:.*]] = arith.shrui %[[X3]], %[[CS3]] : i64 + ! CHECK: %[[R3:.*]] = arith.andi %[[SHR3]], %[[CM3]] : i64 + ! CHECK: %[[X4:.*]] = arith.addi %[[L3]], %[[R3]] : i64 + ! CHECK: %[[CM4:.*]] = arith.constant 270582939711 : i64 + ! CHECK: %[[CS4:.*]] = arith.constant 16 : i64 + ! CHECK: %[[L4:.*]] = arith.andi %[[X4]], %[[CM4]] : i64 + ! CHECK: %[[SHR4:.*]] = arith.shrui %[[X4]], %[[CS4]] : i64 + ! CHECK: %[[R4:.*]] = arith.andi %[[SHR4]], %[[CM4]] : i64 + ! CHECK: %[[X5:.*]] = arith.addi %[[L4]], %[[R4]] : i64 + ! CHECK: %[[CM5:.*]] = arith.constant 127 : i64 + ! CHECK: %[[CS5:.*]] = arith.constant 32 : i64 + ! CHECK: %[[L5:.*]] = arith.andi %[[X5]], %[[CM5]] : i64 + ! CHECK: %[[R5:.*]] = arith.shrui %[[X5]], %[[CS5]] : i64 + ! CHECK: %[[X6:.*]] = arith.addi %[[L5]], %[[R5]] : i64 + ! CHECK: %[[LO:.*]] = fir.convert %[[X6]] : (i64) -> i32 + ! CHECK: %[[C64:.*]] = arith.constant 64 : i128 + ! CHECK: %[[YSH:.*]] = arith.shrui %[[XVAL]], %[[C64]] : i128 + ! CHECK: %[[Y0:.*]] = fir.convert %[[YSH]] : (i128) -> i64 + ! CHECK: %[[CM0:.*]] = arith.constant 6148914691236517205 : i64 + ! CHECK: %[[CS0:.*]] = arith.constant 1 : i64 + ! CHECK: %[[L0:.*]] = arith.andi %[[Y0]], %[[CM0]] : i64 + ! CHECK: %[[SHR0:.*]] = arith.shrui %[[Y0]], %[[CS0]] : i64 + ! CHECK: %[[R0:.*]] = arith.andi %[[SHR0]], %[[CM0]] : i64 + ! CHECK: %[[Y1:.*]] = arith.addi %[[L0]], %[[R0]] : i64 + ! CHECK: %[[CM1:.*]] = arith.constant 3689348814741910323 : i64 + ! CHECK: %[[CS1:.*]] = arith.constant 2 : i64 + ! CHECK: %[[L1:.*]] = arith.andi %[[Y1]], %[[CM1]] : i64 + ! CHECK: %[[SHR1:.*]] = arith.shrui %[[Y1]], %[[CS1]] : i64 + ! CHECK: %[[R1:.*]] = arith.andi %[[SHR1]], %[[CM1]] : i64 + ! CHECK: %[[Y2:.*]] = arith.addi %[[L1]], %[[R1]] : i64 + ! CHECK: %[[CM2:.*]] = arith.constant 1085102592571150095 : i64 + ! CHECK: %[[CS2:.*]] = arith.constant 4 : i64 + ! CHECK: %[[L2:.*]] = arith.andi %[[Y2]], %[[CM2]] : i64 + ! CHECK: %[[SHR2:.*]] = arith.shrui %[[Y2]], %[[CS2]] : i64 + ! CHECK: %[[R2:.*]] = arith.andi %[[SHR2]], %[[CM2]] : i64 + ! CHECK: %[[Y3:.*]] = arith.addi %[[L2]], %[[R2]] : i64 + ! CHECK: %[[CM3:.*]] = arith.constant 8725857424048159 : i64 + ! CHECK: %[[CS3:.*]] = arith.constant 8 : i64 + ! CHECK: %[[L3:.*]] = arith.andi %[[Y3]], %[[CM3]] : i64 + ! CHECK: %[[SHR3:.*]] = arith.shrui %[[Y3]], %[[CS3]] : i64 + ! CHECK: %[[R3:.*]] = arith.andi %[[SHR3]], %[[CM3]] : i64 + ! CHECK: %[[Y4:.*]] = arith.addi %[[L3]], %[[R3]] : i64 + ! CHECK: %[[CM4:.*]] = arith.constant 270582939711 : i64 + ! CHECK: %[[CS4:.*]] = arith.constant 16 : i64 + ! CHECK: %[[L4:.*]] = arith.andi %[[Y4]], %[[CM4]] : i64 + ! CHECK: %[[SHR4:.*]] = arith.shrui %[[Y4]], %[[CS4]] : i64 + ! CHECK: %[[R4:.*]] = arith.andi %[[SHR4]], %[[CM4]] : i64 + ! CHECK: %[[Y5:.*]] = arith.addi %[[L4]], %[[R4]] : i64 + ! CHECK: %[[CM5:.*]] = arith.constant 127 : i64 + ! CHECK: %[[CS5:.*]] = arith.constant 32 : i64 + ! CHECK: %[[L5:.*]] = arith.andi %[[Y5]], %[[CM5]] : i64 + ! CHECK: %[[R5:.*]] = arith.shrui %[[Y5]], %[[CS5]] : i64 + ! CHECK: %[[Y6:.*]] = arith.addi %[[L5]], %[[R5]] : i64 + ! CHECK: %[[HI:.*]] = fir.convert %[[Y6]] : (i64) -> i32 + ! CHECK: %[[CNT:.*]] = arith.addi %[[LO]], %[[HI]] : i32 + ! CHECK: %[[CONE:.*]] = arith.constant 1 : i32 + ! CHECK: %[[RSLT:.*]] = arith.andi %[[CNT]], %[[CONE]] : i32 + ! CHECK: fir.store %[[RSLT]] to %[[BREF]] : !fir.ref +end subroutine poppar16_test