[llvm] [IPSCCP] Infer attributes on arguments (PR #107114)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 9 08:55:50 PDT 2024


dtcxzyw wrote:

> > Missing fold: https://alive2.llvm.org/ce/z/dufVNK
> 
> Isn't this handled by CVP? https://alive2.llvm.org/ce/z/2sDmsW

It seems like a phase-ordering problem.

Reduced reproducer:
```
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

define internal i64 @Abc_Tt6Stretch(i64 %0, i32 noundef %1) {
  %3 = icmp eq i32 %1, 0
  %spec.select = call i32 @llvm.umax.i32(i32 %1, i32 1)
  %.1 = select i1 %3, i32 0, i32 %spec.select
  %4 = icmp eq i32 %.1, 2
  %.06 = select i1 %4, i64 0, i64 %0
  %5 = icmp eq i32 %.1, 1
  %.17 = select i1 %5, i64 1, i64 %.06
  ret i64 %.17
}

define void @Wlc_BlastLut(i64 %0, i32 %1, ptr %2) {
  %4 = icmp slt i32 %1, 6
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  %6 = call i64 @Abc_Tt6Stretch(i64 %0, i32 %1)
  store i64 %6, ptr %2, align 8
  br label %7

7:                                                ; preds = %5, %3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```

Before (0f5033053a3d4dcf27cd488a360e64c48a36c27a):
```
; opt -O3 reduced.ll -S
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
define void @Wlc_BlastLut(i64 %0, i32 %1, ptr nocapture writeonly %2) local_unnamed_addr #0 {
  %4 = icmp slt i32 %1, 6
  br i1 %4, label %5, label %8

5:                                                ; preds = %3
  %6 = icmp eq i32 %1, 2
  %.06.i = select i1 %6, i64 0, i64 %0
  %7 = icmp eq i32 %1, 1
  %.17.i = select i1 %7, i64 1, i64 %.06.i
  store i64 %.17.i, ptr %2, align 8
  br label %8

8:                                                ; preds = %5, %3
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
```
After:
```
; bin/opt -O3 reduced.ll -S
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
define void @Wlc_BlastLut(i64 %0, i32 %1, ptr nocapture writeonly %2) local_unnamed_addr #0 {
  %4 = icmp slt i32 %1, 6
  br i1 %4, label %5, label %9

5:                                                ; preds = %3
  %6 = icmp eq i32 %1, 0
  %spec.select.i = tail call i32 @llvm.umax.i32(i32 %1, i32 1)
  %.1.i = select i1 %6, i32 0, i32 %spec.select.i
  %7 = icmp eq i32 %.1.i, 2
  %.06.i = select i1 %7, i64 0, i64 %0
  %8 = icmp eq i32 %.1.i, 1
  %.17.i = select i1 %8, i64 1, i64 %.06.i
  store i64 %.17.i, ptr %2, align 8
  br label %9

9:                                                ; preds = %5, %3
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```


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


More information about the llvm-commits mailing list