Skip to content

Commit 0d1e762

Browse files
authored
[InstSimplify] Refine abs(min/undef, true) to poison (#118669)
Calls to `@llvm.abs(undef, i1 true)` and `@llvm.abs(INT_MIN, i1 true)` can be optimized to `poison` instead of `undef`. [Alive2](https://alive2.llvm.org/ce/z/Hg-2ug)
1 parent fd02693 commit 0d1e762

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,9 +3018,9 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty,
30183018
assert(C1 && "Must be constant int");
30193019
assert((C1->isOne() || C1->isZero()) && "Must be 0 or 1");
30203020

3021-
// Undef or minimum val operand with poison min --> undef
3021+
// Undef or minimum val operand with poison min --> poison
30223022
if (C1->isOne() && (!C0 || C0->isMinSignedValue()))
3023-
return UndefValue::get(Ty);
3023+
return PoisonValue::get(Ty);
30243024

30253025
// Undef operand with no poison min --> 0 (sign bit must be clear)
30263026
if (!C0)

llvm/test/Transforms/InstSimplify/ConstProp/abs.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare <8 x i8> @llvm.abs.v8i8(<8 x i8>, i1)
66

77
define i8 @undef_val_min_poison() {
88
; CHECK-LABEL: @undef_val_min_poison(
9-
; CHECK-NEXT: ret i8 undef
9+
; CHECK-NEXT: ret i8 poison
1010
;
1111
%r = call i8 @llvm.abs.i8(i8 undef, i1 true)
1212
ret i8 %r
@@ -22,7 +22,7 @@ define i8 @undef_val_min_not_poison() {
2222

2323
define i8 @min_val_min_poison() {
2424
; CHECK-LABEL: @min_val_min_poison(
25-
; CHECK-NEXT: ret i8 undef
25+
; CHECK-NEXT: ret i8 poison
2626
;
2727
%r = call i8 @llvm.abs.i8(i8 -128, i1 true)
2828
ret i8 %r

0 commit comments

Comments
 (0)