[all-commits] [llvm/llvm-project] ab12bb: [CGP] Drop poison-generating flags after hoisting...

Yingwei Zheng via All-commits all-commits at lists.llvm.org
Mon Apr 29 00:52:10 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ab12bba0aad800c1805eca2ea937da958c1854c8
      https://github.com/llvm/llvm-project/commit/ab12bba0aad800c1805eca2ea937da958c1854c8
  Author: Yingwei Zheng <dtcxzyw2333 at gmail.com>
  Date:   2024-04-29 (Mon, 29 Apr 2024)

  Changed paths:
    M llvm/lib/CodeGen/CodeGenPrepare.cpp
    M llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll
    A llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll

  Log Message:
  -----------
   [CGP] Drop poison-generating flags after hoisting (#90382)

See the following case:
```
define i8 @src1(i8 %x) {
entry:
  %cmp = icmp eq i8 %x, -1
  br i1 %cmp, label %exit, label %if.then

if.then:
  %inc = add nuw nsw i8 %x, 1
  br label %exit

exit:
  %retval = phi i8 [ %inc, %if.then ], [ -1, %entry ]
  ret i8 %retval
}

define i8 @tgt1(i8 %x) {
entry:
  %inc = add nuw nsw i8 %x, 1
  %0 = icmp eq i8 %inc, 0
  br i1 %0, label %exit, label %if.then

if.then:                                          ; preds = %entry
  br label %exit

exit:                                             ; preds = %if.then, %entry
  %retval = phi i8 [ %inc, %if.then ], [ -1, %entry ]
  ret i8 %retval
}
```
`optimizeBranch` converts `icmp eq X, -1` into cmp to zero on RISC-V and
hoists the add into the entry block. Poison-generating flags should be
dropped as they don't still hold.

Proof: https://alive2.llvm.org/ce/z/sP7mvK
Fixes https://github.com/llvm/llvm-project/issues/90380



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list