bool KnownBitsComputed = false;
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
switch (II->getIntrinsicID()) {
+ case Intrinsic::abs: {
+ if (DemandedMask == 1)
+ return II->getArgOperand(0);
+ break;
+ }
case Intrinsic::bswap: {
// If the only bits demanded come from one byte of the bswap result,
// just shift the input byte into position to eliminate the bswap.
ret <4 x i8> %t
}
+; abs() doesn't change the low bit.
+
define i32 @demand_low_bit(i32 %x) {
; CHECK-LABEL: @demand_low_bit(
-; CHECK-NEXT: [[A:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
-; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], 1
+; CHECK-NEXT: [[R:%.*]] = and i32 [[X:%.*]], 1
; CHECK-NEXT: ret i32 [[R]]
;
%a = call i32 @llvm.abs.i32(i32 %x, i1 false)
ret i32 %r
}
+; Int min behavior doesn't affect the transform.
+
define <3 x i82> @demand_low_bit_int_min_is_poison(<3 x i82> %x) {
; CHECK-LABEL: @demand_low_bit_int_min_is_poison(
-; CHECK-NEXT: [[A:%.*]] = call <3 x i82> @llvm.abs.v3i82(<3 x i82> [[X:%.*]], i1 true)
-; CHECK-NEXT: [[R:%.*]] = shl <3 x i82> [[A]], <i82 81, i82 81, i82 81>
+; CHECK-NEXT: [[R:%.*]] = shl <3 x i82> [[X:%.*]], <i82 81, i82 81, i82 81>
; CHECK-NEXT: ret <3 x i82> [[R]]
;
%a = call <3 x i82> @llvm.abs.v3i82(<3 x i82> %x, i1 true)
ret <3 x i82> %r
}
+; Negative test - only low bit is allowed.
+
define i32 @demand_low_bits(i32 %x) {
; CHECK-LABEL: @demand_low_bits(
; CHECK-NEXT: [[A:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)