[llvm] [ConstraintElim] Add facts implied by llvm.abs (PR #73189)

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 25 22:48:35 PST 2023


alexander-shaposhnikov wrote:

P.S. I'd like to expand my previous comment a bit - I've just checked and currently InstSimplify doesn't handle these cases
(if the args are not constant):
```
./bin/opt -passes=instsimplify -S ~/abs.ll 
```
```
define i1 @abs_int_min_is_not_poison(i32 %arg) {
  %abs = tail call i32 @llvm.abs.i32(i32 %arg, i1 false)
  %cmp = icmp sge i32 %abs, %arg
  ret i1 %cmp
}

define i1 @abs_int_min_is_poison(i32 %arg) {
  %abs = tail call i32 @llvm.abs.i32(i32 %arg, i1 true)
  %cmp = icmp sge i32 %abs, %arg
  ret i1 %cmp
}

define i1 @abs_plus_one(i32 %arg) {
  %abs = tail call i32 @llvm.abs.i32(i32 %arg, i1 true)
  %abs_plus_one = add nsw i32 %abs, 1
  %cmp = icmp sge i32 %abs_plus_one, %arg
  ret i1 %cmp
}

define i1 @abs_constant_negative_arg() {
  ret i1 true
}

define i1 @abs_constant_positive_arg() {
  ret i1 true
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #0

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```
To me teaching ConstrainElim about intrinsics seems to be a better idea than putting more patterns into InstSimplify,
but maybe I'm missing something. 


https://github.com/llvm/llvm-project/pull/73189


More information about the llvm-commits mailing list