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

Yingwei Zheng via All-commits all-commits at lists.llvm.org
Tue Apr 30 11:07:43 PDT 2024


  Branch: refs/heads/release/18.x
  Home:   https://github.com/llvm/llvm-project
  Commit: 6350acdb134d2e494c029ef2f83ccbc1a1462ba3
      https://github.com/llvm/llvm-project/commit/6350acdb134d2e494c029ef2f83ccbc1a1462ba3
  Author: Yingwei Zheng <dtcxzyw2333 at gmail.com>
  Date:   2024-04-30 (Tue, 30 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

(cherry picked from commit ab12bba0aad800c1805eca2ea937da958c1854c8)



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